C++
Create an application named CarDemo that declares at least two Car objects and demonstrates how they can be incremented using an overloaded ++ operator.
Create a Car class that contains the following properties:
Include two overloaded constructors. One accepts parameters for the model and miles per gallon; the other accepts a model and sets the miles per gallon to 20.
Overload a ++ operator that increases the miles per gallon value by 1. The CarDemo application creates at least one Car using each constructor and displays the Car values both before and after incrementation.
Code:
#include <iostream>
using namespace std;
class Car
{
public:
string model;
double mpg;
// This constructor takes model and mpg and assigns them as values to class variables
Car(string model,double mpg)
{
this->model = model;
this->mpg = mpg;
}
// This constructor takes model number and assigns it to class variable and the mpg is set to 20
Car(string model)
{
this->model = model;
this->mpg = 20;
}
// Overloading ++ operator
Car operator ++ () {
// Pre incrementing the mpg
++mpg;
// Returning an new object
return Car(model,mpg);
}
};
// Main function
int main() {
// Creating two objects of Car class
Car tesla = Car("Tesla");
Car mustang = Car("Mustang",27);
// Printing the contents of the objects before pre increment
cout<<"Before increment"<<endl;
cout<<"Model name:"<<tesla.model<<endl;
cout<<"Miles per gallon:"<<tesla.mpg<<endl;
cout<<"Model name:"<<mustang.model<<endl;
cout<<"Miles per gallon:"<<mustang.mpg<<endl;
cout<<"\n\n";
// Pre incrementing the miles per gallon
++tesla;
++mustang;
// Printing the contents of the objects after pre increment
cout<<"After increment"<<endl;
cout<<"Model name:"<<tesla.model<<endl;
cout<<"Miles per gallon:"<<tesla.mpg<<endl;
cout<<"Model name:"<<mustang.model<<endl;
cout<<"Miles per gallon:"<<mustang.mpg<<endl;
return 0;
}
Sample Output:

C++ Create an application named CarDemo that declares at least two Car objects and demonstrates how...
C+ Create an application named CarDemo that declares at least two Car objects and demonstrates how they can be incremented using an overloaded ++ operator. Create a Car class that contains the following properties: Model - The car model (as a string) Mpg The car's miles per gallon (as a double) Include two overloaded constructors. One accepts parameters for the model and miles per gallon; the other accepts a model and sets the miles per gallon to 20. Overload a...
C# Create an application named JobDemo that declares and uses Job objects. The Job class holds job information for a home repair service. The class has five properties that include: JobNumber - The job number Customer - The customer name Description - The job description Hours - The estimated hours price - The price for the job Create a constructor that requires parameters for all the data except price. Include auto-implemented properties for the job number, customer name, and job...
Programming Logic and Design, comprehensive, 8 edition. Chapter 11, PE 5a Create a class named Trip that includes four string variables; destination (for example, "air"), departure date (for example, "12/15/2015"), and trip's purpose (for example, "business") Include tow overloaded constructors. The default constructor sets each field to "XXX". The nondefault constructor accepts four parameters- one for each field. include two overloaded display() methods. The parameterless version displays all the Trip details. The second version accepts a string that represents a...
Using C#: Create an application class named BillDemo that instantiates objects of two classes named Bill and OverdueBill, and that demonstrates all their methods. The Bill class includes auto-implemented properties for the name of the company or person to whom the bill is owed and for the amount due. Also, include a ToString() method and returns a string that contains the name of the class (using GetType()) and the Bill’s data fields values. Create a child class named OverdueBill that...
C++ Program 1. Create a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Your application declares an array of 12 BaseballGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or “Tie” if the score is a tie. (main.cpp,...
Create a program named TilingDemo that instantiates an array of 10 Room objects and demonstrates its methods. The Room constructor requires parameters for length and width fields; use a variety of values when constructing the objects. The Room class also contains a field for floor area of the Room and number of boxes of tile needed to tile the room. Both of these values are computed by calling private methods. A room requires one box of tile for every 12...
Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design: You will create a class and then use the provided test program to make sure it works. This means that your class and methods must match the names used in the test program. Also, you need to break your class implementation into multiple files. You should have a car.h that defines the car class, a list.h, and a list.cpp. The link is a struct...
Create a C# program named PaintingDemo that instantiates an array of eight Room objects and demonstrates the Room methods. The Room constructor requires parameters for length, width, and height fields; use a variety of values when constructing the objects. The Room class also contains a field for wall area of the Room and number of gallons of paint needed to paint the room. Both of these values are computed by calling private methods. Include read-only properties to get a...
C# VISUAL STUDIO CONSOLE App(.NET Framework) Create an application named ShapesDemo that creates several objects that descend from an abstract class called GeometricFigure. Each GeometricFigure includes a height, a width, and an area. Provide get and set accessors for each field except area; the area is computed and is read-only. Include a method called ComputeArea() that computes the area of the GeometricFigure. Next you will create two additional classes derived from the GeometricFigure class Rectangle and Square.
Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods. The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings). Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of...