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;
//for any clarification please do comments. if you found this solution useful, please give me thumbs up
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 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 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, 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. 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++ 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 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 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...
What if you had to write a program that would keep track of a
list of rectangles? This might be for a house painter to use in
calculating square footage of walls that need paint, or for an
advertising agency to keep track of the space available on
billboards.
The first step would be to define a class where one object
represents one rectangle's length and width. Once we have class
Rectangle, then we can make as many objects of...
Using Java write a program that performs the following: 1. Define a class that contains an array of type int as a data member. 2. Define a constructor that creates an array of 1024 elements and assigns it to the class data member. The constructor shall populate the elements with random numbers ranging in value from 1 to 1024. 3. Define and implement a search() method that take a parameter of type int and returns the index location if the...