Question
(Member Functions and Constructors, 40 points) write definitions for the member functions and constructors in the following class. class Car { string brand; // ex
(Member Functions and Constructors, 40 points) write definitions for the member functions and constructors in the following class.
class Car {
string brand; // ex BMW
int year;
Car(); // assign some default values for brand and year.
Car(string, int);
string getBrand();
int getyear();
void setBrand(string);
void setYear(int);
In the main function declare two objects of type car, the first object should be initialized using the default constructor, while the second object should be initialized using the non-default constructor. Print the values of the private data members for each object using the accessor functions.
Change the values of the private data members for the previous objects using the mutator functions, and then print these new values using the accessor functions.
Declare a third object of type Car and initialize it using the default constructor.
Declare a pointer of type Car, initialize this pointer to point to the third object you created in the previous step. Print the data members of the third object using the pointer.
Part 2
(Array of Objects, Friend Functions and Classes, 60 points) write the definitions for the constructors in the following class. And write prototypes and definitions for the accessor and mutator functions to access and mutate the data members (6 functions).
class Building {
string address; // ex Park Ave
int No_floors;
double area;
Building(); // assign values for address, No_floors, and area.
Building(string, int,double);
Building(string, int);
Building(double,string, int);
Change the definition of the default constructor to allocate an array of 3 integers dynamically in addition to the previous job of assigning values for the data members.
Add a destructor for this class, the destructor should release the memory that was allocated dynamically by the constructor.
In the main function, declare an array of 5 objects of type Building and initialize these objects using different constructors.
For each object in the previous step call the accessor and mutator functions to set and get the values of the data members.
Change class Building to have a friend function which has the following prototype
Building getBuildingArea(Building*);
In the main function declare an object of type Building, pass this object to getBuildingArea function, which should return an object of type building that has the same area as the area of the object you passed to the function.
Change class Building to have a friend class which has the following definition
class City {
string name;
City(string s) {name=s;}
void getAddress(Building& b) {cout< In the main function declare an object of type Building and an object of type City, pass the building object to the function getAddress(Building& b) which is a member function of City object.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started