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

1: Write the header file Car.h for the Car class. The Car class has three data m

ID: 3771342 • Letter: 1

Question

1: Write the header file Car.h for the Car class. The Car class has three data members: miles_per_gallon (double), fuel (double), and model (string). The Car class has a constructor that initializes each data member. The Car class has four additional member functions:
get_model : no parameters, returns model
drive : double miles parameter, returns nothing
add_fuel : double gallons parameter, returns nothing
low_on_fuel : no parameters, returns true or false
Do not provide the implementation of the member functions.

2: Write the source code fileSquare.cpp. Include necessary header files and implementation of each member function of the followingSquareclass. class Square{public: Square(double initial_length, string initial_color); doubleget_length() const; stringget_color() const; doubleget_area() const;private: double length; string color;}; The area of a square is length x length.

3: Write a void function named sort2 that takes two string parameters and sorts them. The function swaps the values of the string parameters if the 1st string is lexicographically greater than the 2nd string and otherwise leaves the strings unchanged. For example: string s1 = "Orange";string s2 = "Apple";sort2(s1, s2); // now s1 is “Apple" and s2 is "orange"

Explanation / Answer

1:
class Car
{
private:
   double miles_per_gallon;
   double fuel;
   string model;

public:
   Car(double a, double b, string c):miles_per_gallon(a),fuel(b),model(c){}
   string get_model;
   void drive();
   void add_fuel();
   bool low_on_fuel();

};


2 and 3:

#include <iostream>
#include <string>

using namespace std;

class Square
{
public:
Square(double initial_length, string initial_color);
double get_length() const;
string get_color() const;
double get_area() const;

private:
double length;
string color;
};

Square::Square(double initial_length, string initial_color):length(initial_length),color(initial_color)
{
//empty
}

double Square::get_length() const
{
return length;
}
string Square::get_color() const
{
return color;
}
double Square::get_area() const
{
return length*length;
}


void sort2(string& s1, string& s2)
{
string temp;

if(s1>s2)
{
temp = s1;
s1 = s2;
s2 = temp;
}
}

int main()
{
string s1 = "Orange";
string s2 = "Apple";

cout<<"Earlier s1="<<s1<<" s2="<<s2<<endl;
sort2(s1,s2);
cout<<"After swapping s1="<<s1<<" s2="<<s2<<endl<<endl;;

s2 = "Orange";
s1 = "Apple";
cout<<"Earlier s1="<<s1<<" s2="<<s2<<endl;
sort2(s1,s2);
cout<<"After swapping s1="<<s1<<" s2="<<s2<<endl;

Square obj(2,"black");
cout<<"Sqaure obj has length = "<<obj.get_length()<<" color = "<<obj.get_color()<<" area = "<<obj.get_area()<<endl;

return 1;
}

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