Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The app we were taught using is visual studios 2015 with the format following: #

ID: 3861150 • Letter: T

Question

The app we were taught using is visual studios 2015 with the format following:

#include <iostream>;

using namespace std;

int main() {

system("pause");

return 0; }

*************************************** This is what I have so far. If it helps please build of of this program****************************************

#include<iostream>

#include<string>

using namespace std;

const int SIZE = 30;

struct gasMileage {

double miles;

double gallons;

};

class Car {

private:

char make[SIZE];

char model[SIZE];

char color[SIZE];

int cylinder;

gasMileage gs;

public:

Car::Car();

Car::Car(char[], char[], char[], int, double, double);

void setMileage(double m, double g);

void setModel(string);

void setMake(char[]);

void setColor(char[]);

void setCylinder(int);

double getMileage();

string getModel();

char *getMake();

char *getColor();

//int getCylinder();

};

Car::Car() {

char *make = new char[SIZE];

char *model = new char[SIZE];

char *color = new char[SIZE];

cylinder = 0;

gs.miles = 0;

gs.gallons = 0;

}

Car::Car(char make[], char model[], char color[], int cylinder, double miles, double gallons) {

make = make;

model = model;

color = color;

cylinder = cylinder;

gs.miles = miles;

gs.gallons = gallons;

}

void Car::setMileage(double miles, double gallons) {

gs.miles = miles;

gs.gallons = gallons;

}

void Car::setModel(string model1) {

model = model1;

}

void Car::setMake(char make[]) {

*make = make[0];

}

void Car::setColor(char color[]) {

*color = color[0];

}

/*ask*/void Car::setCylinder(int cylinder) {

cylinder = cylinder;

}

double Car::getMileage() {

return gs.miles / gs.gallons;

}

string Car::getModel() {

string s="";

int j = sizeof(model);

cout << "MSIZE=" << j << endl;

for (int i = 0;i < j;i++)

{

cout << model[i];

//s += model[i];

}

return s;

}

char* Car::getMake() {

return make;

}

char* Car::getColor() {

return color;

}

/*int getCylinder() {

}*/

int main() {

char make[] = "Toyota";

char model[] = "Camry";

char color[] = "Silver";

int cylinder = 4;

double miles = 100;

double gallons = 10;

Car Toyota(make, model, color, cylinder, miles, gallons);

cout << "Milage = " << Toyota.getMileage() << endl;

Toyota.setMileage(40, 5);

cout << "Milage = " << Toyota.getMileage() << endl;

cout << "Model = " << Toyota.getModel() << endl;

Toyota.setModel("LE");

cout << "Model = " << Toyota.getModel() << endl;

cout << "Make = " << Toyota.getMake() << endl;

Toyota.setMake("2007");

cout << "Make = " << Toyota.getMake() << endl;

cout << "Color = " << Toyota.getColor() << endl;

Toyota.setColor("Silver");

cout << "Color = " << Toyota.getColor() << endl;

system("pause");

return 0;

}

Construct a class named Car that has data members: make - char[], model - char[], color- char[], model-charll, color-cih cylinders (etc: 4 or 6)-int, gas mileage (etc: 14/24) - struct. The class should have the following member functions constructor that sets each member to 0 or null, · constructor that sets each members as user creates destructor to free up any data, . SetMake() to print make, model . SetMileage() to print "City/Highway: 14/24" . SetCylinder() to print "4 Cylinders" or "6 Cylinders" .SetColor) to print color of the vehicle . GetMake) to print make, model . GetMileage() to print "City/Highway: 14/24" GetCylinder() to print "4 Cylinders" or "6 Cylinders" GetColor() to print color of the vehicle · Now, create two cars. & print descriptions of these two cars in main using couts

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;

struct gasMileage {
double miles;
double gallons;
};

#define SIZE 40
class Car {

private:

char make[SIZE];
char model[SIZE];
char color[SIZE];
int cylinder;
gasMileage gs;

public:
Car::Car();
Car::Car(char *, char *, char*, int, double, double);
void setMileage(double m, double g);
void setModel(char[]);
void setMake(char[]);
void setColor(char[]);
void setCylinder(int);
double getMileage();
void getModel();
void getMake();
void getColor();
void getCylinder();
};

Car::Car()
{
   memset(make,0,sizeof(make));
   memset(model,0,sizeof(model));
   memset(color,0,sizeof(color));
   cylinder = 0;
   gs.miles = 0;
   gs.gallons = 0;
}

Car::Car(char make[], char model[], char color[], int cylinder, double miles, double gallons)
{

   memcpy(this->make,make,SIZE);
   memcpy(this->model,model,SIZE);
   memcpy(this->color,color,SIZE);
   cylinder = cylinder;
   gs.miles = miles;
   gs.gallons = gallons;

}

void Car::setMileage(double miles, double gallons)
{
gs.miles = miles;
gs.gallons = gallons;
}

void Car::setModel(char model1[])
{
   memcpy(this->model,model1,SIZE);
}

void Car::setMake(char make[]) {
   memcpy(this->make,make,SIZE);
}

void Car::setColor(char color[]) {
   memcpy(this->color,color,SIZE);

}

void Car::setCylinder(int cylinder) {
   this->cylinder = cylinder;
}

double Car::getMileage() {

return gs.miles / gs.gallons;

}

void Car::getModel() {
cout << "Model = " << model << endl;


}

void Car::getMake() {
cout << "Make = " << make << endl;

}

void Car::getColor() {
   cout << "Color = " << this->color<< endl;
}

void getCylinder() {
cout << "Cylinder = " << endl;
}

int main() {


char make[] = "Toyota";
char model[] = "Camry";
char color[] = "Silver";
int cylinder = 4;
double miles = 100;
double gallons = 10;

Car Toyota(make, model, color, cylinder, miles, gallons);
Toyota.setMileage(40, 5);
Toyota.getModel() ;

Toyota.setModel("LE");
Toyota.getModel();

Toyota.getMake();

Toyota.setMake("2007");

Toyota.getMake();
Toyota.getColor();
Toyota.setColor("Silver");
Toyota.getColor();
system("pause");

return 0;

}

OUTPUT:

Model = Camry
Model = LE
Make = Toyota
Make = 2007
Color = Silver
Color = Silver
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote