C++, no pointer, #inlclude <iostream>, using namespace std 1. Using separate sou
ID: 3710285 • Letter: C
Question
C++, no pointer, #inlclude <iostream>, using namespace std
1. Using separate source files and header files as appropriate, create a class to represent desks. 1. A desk object has attributes of color (string) and number of drawers (integer) 2. Member functions are 1. default constructor with default parameter values of "Steel Blue" and 4, and that displays "IntConstructor called n 2. individual get methods for each attribute that are written in-line 3. a get method that uses pass-by-reference for both parameters and has return-type void 4. one set method that sets both attributes (NOT to be written in-line) 5. PrintMe method that displays "I'm a desk with drawers.", replacing and with the appropriate attribute values 6. Destructor that displays "InltDestructor called " 2. Write a complete program that uses the desk class. 1. Declare a vector of 5 objects of desk class 2. Declare a single desk object and initialize it at declaration to have color "Silver" 3. Call the PrintMe method of the single object 4. Call a void function that has a vector of desks as its parameter. That function should: 1. Ask the user for 5 colors and 5 numbers and assign them to each desk in the vector 2. For the 2nd desk, if the color's name is 4 or more characters long, change the 3rd character of the name to'# 3. Open file "output.txt" and write to it using the same text that PrintMe uses for all desks in your vector 4. Close the output fileExplanation / Answer
#include<iostream>
#include<string>
#include <stdio.h>
#include <AssertMacros.h>
using namespace std;
class desk {
private:
string colour;
int number;
public:
desk() {
colour = "Steel Blue";
number = 4;
cout<<" Default constructor called ";
}
inline string getColor() {
return colour;
}
inline int getNumber() {
return number;
}
void setData(string color, int n){
colour = color;
number = n;
}
void getData(string *c, int *n){
c = &colour;
n = &number;
}
void printMe() {
cout<< "I am " << colour << " desk with" << number << " drawers ";
}
~desk() {
cout << "Destructor called ";
}
};
int main() {
desk d;
d.setData("Silver", 3);
d.printMe();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.