Question
c++, use the skeleton code to make a program of the following
include <iostream> tinclude <string> using namespace std; class car public: //define your functions here, at least 5 private:
For this lab, write a program that does the following: Creates a class based on the car skeleton code (you may make modificat
include tinclude using namespace std; class car public: //define your functions here, at least 5 private: string name; int mpg; double price int horsepower; // feel free to add more atributes int main() // create you objects, call your functions // define member functions here
For this lab, write a program that does the following: Creates a class based on the car skeleton code (you may make modifications) . Creates 5 car objects (you do not need to prompt the user for these, they can be hard coded in) Allows the user to select 3 cars to compare (you may want to store these 3 objects in an array or vector) . Adds at least 5 meaningful member functions, some of which that compare 3 cars to each other. These functions could include: find best gas mileage, find lowest price find greatest horsepower, etc . In main, the program I/O should: .Let the user choose which 3 cars to compare Let the user select which comparison(s) they want to run .
0 0
Add a comment Improve this question Transcribed image text
Answer #1

cpp code:

#include <iostream>

using namespace std;

//car class
class car
{

public:
//constructor
car()
{

}
//set the values
void setValues(string n,int m,double pr,int hp,int ca)
{
this->name = n;
this ->mpg=m;
this->price=pr;
this->horsepower = hp;
this->capacity= ca;
}
//return the mileage
int getMileage()
{
return mpg;
}
//return the price
double getPrice()
{
return price;
}
//return the hp
int getHorsepower()
{
return horsepower;
}
//return the capacity of fuel tank
int getCapacity()
{
return capacity;
}
//return the name
string getName()
{
return name;
}
//variables
private:
string name;
int mpg;
double price;
int horsepower;
int capacity;
};
//function declarations
string* compare(car c[]);
int main()
{
car c[5]; //array of objects of car class
  
//set vlaues
c[0].setValues("Datsun",28,4.1,250,35);
c[1].setValues("Renault",22,5.0,350,28);
c[2].setValues("Tiago",30,3.5,220,27);
c[3].setValues("BMW",35,8.0,330,32);
c[4].setValues("Ford",29,7.2,250,30);

string* carName;

carName =compare(c); //call the compare function
  
//print the 1st three names of car
for(int i=0;i<3;i++)
cout<<"\n"<<i+1<<". "<<carName[i];

cout << endl;
return 0;
}
//get the name of best mileage car
string bestMileage(car c[] )
{
int best = 0;
int index;
for(int i=0;i<5;i++)
{
if(best<c[i].getMileage()){
best= c[i].getMileage();
index= i;
}
}
return c[index].getName();
}
//return lowest price car name
string lowestPrice(car c[])
{
double best = 99999;
int index;
for(int i=0;i<5;i++)
{
if(best>c[i].getPrice()){
best= c[i].getPrice();
index= i;
}
}
return c[index].getName();
}

//return greatest hp car name
string greatestHP(car c[])
{
int best =0;
int index;
for(int i=0;i<5;i++)
{
if(best<c[i].getHorsepower()){
best= c[i].getHorsepower();
index= i;
}
}
return c[index].getName();
}

//return greatest capacity car name
string greatestCapacity(car c[])
{
int best =0;
int index;
for(int i=0;i<5;i++)
{
if(best<c[i].getCapacity()){
best= c[i].getCapacity();
index= i;
}
}
return c[index].getName();
}

//compare the cars and get three best car
string* compare(car c[])
{
string* carObject= new string[3];;

carObject[0]= bestMileage(c);
carObject[1]= greatestHP(c);
carObject[2]= greatestCapacity(c);

if(carObject[0]==carObject[1])
carObject[1]= lowestPrice(c);
if(carObject[1]==carObject[2])
carObject[2]= lowestPrice(c);
if(carObject[0]==carObject[2])
carObject[2]= lowestPrice(c);

return carObject;


}

output;

DAcpp CarComparision bin Debug CarComparision.exe BMW 2. Renault 3. Datsun Process returned 0 〈0x0〉 execution time : 0.019 s

//for any clarification please do comments. if you found this solution useful, please give me thumbs up

Add a comment
Know the answer?
Add Answer to:
C++, use the skeleton code to make a program of the following
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 C program by completing the following skeleton program. /* file minmax.c  **************************************** *   ...

    Write a C program by completing the following skeleton program. /* file minmax.c  **************************************** *        a C program skeleton for the problem *        Find the minimum and maximum values in an array **********************************************************/ #include <stdio.h> /* DATA segment: Global variables */ #define SIZE 10         int arr[SIZE] = { -5, 0xffffface, 0x31, 52, 054, /* base 8 */                         0,...

  • Code the following Program in C++ Define a class named Payment that contains a member variable...

    Code the following Program in C++ Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods.    Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s)....

  • A liter is 0.264179 gallons. Write a program that will read in the number of liters...

    A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon. After doing this... Modify your...

  • Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the...

    Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the call to addFuel in the main program with a call to the accessor and mutator for the fuel amount to achieve the same effect (add 5 gallons of fuel to the existing fuel in the Toyota Camry). Test your program again to make sure it works and produces the same output. Part 2: Add functions to remove duplicate code * In the main program,...

  • c++ driver and car are independed classes 1. Create a class Car, which has a color, engine, horsepower, fuel, FuelLevel, year of manufacturing and driver which can be defined by name, age, licen...

    c++ driver and car are independed classes 1. Create a class Car, which has a color, engine, horsepower, fuel, FuelLevel, year of manufacturing and driver which can be defined by name, age, licenseNumber. Create the corresponding OOP in For each class (Driver, Car) write a header file and the class implementation -In the main function do the following: from that class in main function. L.1 Write a function that will print the total number of objects created 12 Define an...

  • ​c++ program that takes user input from the console and store the data into a linked list.

    c++ program that takes user input from the console and store the data into a linked list. The input made of 4 objects associated to a car: model, make, mileage and year. My program should take the how many inputs the user want to make, followed by the inputs themselves. After the input, my program should print the data inside the linked list. So far, the issue is that my program print some of the input, but not all. Input sample:3HondaSentra89002017ToyotaCamri1098271999NissanSentra87261987current...

  • C/C++ Final Project PROGRAM DUE MONDAY OF FINALS WEEK. Minimum requirements, the program must include the...

    C/C++ Final Project PROGRAM DUE MONDAY OF FINALS WEEK. Minimum requirements, the program must include the following features: Create a program that interacts with the user. Use at least 3 objects (instances of different classes) Use at least one example of inheritance Use at least one pointer Use at least one pass by reference Use at least one overloaded function Use separate files for class definition, class function definition, cpp file that has main Use at least 2 loops Use...

  • C++ program please provide code only for class counterType.h, counterTypeImp.cpp, and main.cpp. Separately code it. Define...

    C++ program please provide code only for class counterType.h, counterTypeImp.cpp, and main.cpp. Separately code it. Define a class counterType to implement a counter. Your class must have a private data member counter of type int. Define a constructor that accepts a parameter of type int and initializes the counter data member. Add functions to: Set counter to the integer value specified by the user. Initialize counter to 0. Return the value of counter with a function named getCounter. Increment and...

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • c program Your teacher want to find out who is the most hardworking student in class!...

    c program Your teacher want to find out who is the most hardworking student in class! They want to input the names according to the order they fell asleep, then print their names in the reverse order. Although you can create an array large enough to store all names, your teacher don’t want to waste our precious memory! The first line of the input is an integer x, which indicate the number of students in class. Then there are x...

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