Question
in c++ thankyou.

1. Using C++, write a program to simulate a cooking) stove. This stove is represented as a class named stove that has the pro
stove kenmore(/* normal */, /* off */, /* on */, /* off */, /* off */); cout << kenmore. GetState() << endl; cout << kenmore.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Code :-

Stove.h

#include<iostream>
#include<string>
#include <thread>
#include <chrono>
using namespace std;

class Stove
{
string state;
int p;
bool elements[4];
public:
Stove() //default
{
    state = "normal";
    p=4;
   }
//parameter constructor
Stove(string s, bool e[],int size)
{
    state=s;
    for(int i=0;i<size;++i)
        elements[i]=e[i];
    p=size;
}
//destructor
~Stove()
{
    cout<<"Stove shutting down\n";

}
string GetState()
{
    return state;
}
//set state
void SetState(string s)
{
    state=s;
}

int GetP()
{
    return p;
}
void SetElement(int n,bool q)
{
    if(n>=p || n<0)
        return;
    elements[n]=q;
}
void clean()
{

    for(int i=0;i<p;++i)
        elements[i]=false;
    this_thread::sleep_for(chrono::seconds(5));
    if(state.compare("clean")!=0)
    cout<<"Error occurred\n";
}

void boil(int n)
{
    if(state.compare("normal")!=0 || elements[n]==false)
        cout<<"Error stove is not working\n";
    elements[n]=true;
    this_thread::sleep_for(chrono::seconds(3));
}
};

Main.cpp

#include<iostream>
#include "stove.h"
using namespace std;


int main()
{
   bool el[4]={false,true,false,false};
   Stove kenmore("normal",el,4);
   cout<<kenmore.GetState()<<endl;
   cout<<kenmore.GetP()<<endl;
   kenmore.SetElement(3,true);
   cout<<kenmore.GetP()<<endl;
   kenmore.boil(0);
   kenmore.boil(1);
   kenmore.boil(2);
   cout<<kenmore.GetP()<<endl;
   kenmore.SetElement(1,false);
   kenmore.clean();
   kenmore.SetState("clean");
   kenmore.clean();
   cout<<kenmore.GetState()<<endl;
   cout<<kenmore.GetP()<<endl;
   return 0;
}

Screenshot of output :-

normal 4 4 Error stove is not working Error stove is not working 4 Error occurred clean 4 Stove shutting down Process exited

Add a comment
Know the answer?
Add Answer to:
in c++ thankyou. 1. Using C++, write a program to simulate a cooking) stove. This stove...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to create a game map. A game map is a 2D array of...

    Write a program to create a game map. A game map is a 2D array of regions, or tiles, of a world, as in the example of the figure to the right . For example, a tile with a value of 0 might represent water, 1 might represent land, 2 might represent a mountain and so forth. This map is represented as a class named CMap that has the properties: • A 2D array, having a height and width of...

  • C++ problem with dynamic arrays is that once the array is created using the new operator...

    C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...

  • Using the below files, Write a program that reads a document containing endnotes indicated in this...

    Using the below files, Write a program that reads a document containing endnotes indicated in this manner, collects them in a queue, and prints them on the screen. For this lab, you will create a text file called sample.txt and put the following paragraph in it. This part is the beginning. {This part is the footnote.} This part is the end. /* Queue.h contains the declaration of class Queue. Basic operations: Constructor: Constructs an empty queue empty: Checks if a...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo t...

    Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...

  • This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

    This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • HI, I am having trouble finsihing this program i was wondering if someone could help me....

    HI, I am having trouble finsihing this program i was wondering if someone could help me. Thanks in adavnce. Here is the code that I have so far..... //Stack.h // implementation file for the stack class #include <iostream> using namespace std; const int stack_size = 100; class stack { private: char data [stack_size]; // elements in the stack int top; // index of the top element of the stack public: stack (); // constructor creates an empty stack void push...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT