Write a C++ program to implement a suitable data structures (using array) of marble plates

 




Write a C++ program to implement a suitable data structures (using array) of marble plates. Your program should cover the following scenario, Suppose a waiter in a hotel is collecting plates from different tables and giving to dish washer. Dish washer is washing plates and throwing them into rack of plates. Some plates hit others very hard to break other (one above it) and/or itself. You need to develop an application that will find how many plates are broken and plates from which tables are broken.

You will identify plates with unique numeric identity number. Every 5th plate thrown into rack will break itself and one plate below it while every 7th plate will only break itself.

Answer:

#include "stdafx.h"

#include "iostream"

#include "conio.h"

using namespace std;

class Dishwasher

{

private:


     int data[10];

     int top;

     int bottom;

     int size;

public:

     Dishwasher() {

           top = -1;

           bottom = 0;

           size = 10;

     }

     void push(int x)

     {

           if (top = -1)

           {

                top = NULL;

                data[top] = x; 

           }

           else

           {

                data[++top] = x;

           }

     }

     void pop()

     {

           cout << "Plate " << data[top] << " is broken." << endl;

           data[top] = 0;

           top--;

     }

};

int _tmain(int argc, _TCHAR* argv[])

{

     Dishwasher d1;

           int count = 0;

     int size;

     int identity[10];

     cout << "Enter No Of plates to insert....." << endl;

     cin >> size;

     for (int i = 0; i < size; i++)

     {

           cout << "Enter identy number of plate....";

           cin >> identity[i];

     }

     for (int i = 0; i < size; i++)

     {

     if (identity[i] % 5 == 0)

     {

     cout << "Plate " << identity[i] << " is broken." << endl;

           d1.pop();

           count = count + 2;

     }

     else if (identity[i] % 7 == 0) {

     cout << "Plate " << identity[i] << " is broken." << endl;

 

                count++;

           }

           else

           {

                d1.push(identity[i]);

           }

     }

     cout << "Total broken plates =" << count << endl;

     _getch();

     return 0;

}

Thank You!!!........)






Comments

Popular posts from this blog

Oop(Object Oriented Programming) Project for final year students

Linklist all concepts using Dynamic arrays(using nodes)