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

I need help, please only post if answer is real, and about this question. Thank

ID: 645214 • Letter: I

Question

I need help, please only post if answer is real, and about this question. Thank you.

write a C++ source file with the
Class name: Vehicle.
It has private attributes
Car Type (string)
Car Name (string)
Car Year (int) 1 = 1970, 2 = 1980, 3 = 1990, 4= 2000;
Car Rank (double) 0.0-4.0
the Public Member Functions:
1) Public Constructors
    - a default constructor with no paramaters
   -a constructor with paramaters, one paramater for each attribute.
2) Public Member Functions
   - set() method for setting value of each attribute
   -The set() method for car year - before assigning the incomin value, check to see if the incoming value is 1, 2, 3, 4. If its not, assign 0, and print to screen, value not legal.
- a get() method for each attribute.
- a method called Decide, to decide if car is worthy to purchase. Following this: If car is 2000 and rank is 3.8 or higher, return a true value for granting worthyness to purchase.    Otherwise return false value, that means car is not worthy to purchase.
In the same source file write the main() function.
1) create 2 specific Vehicle objects, use object names c1 and c2, giving them specific attribute values. Either through constructor with paramaters, or through set statements after they are created.
2) For each vehicle, retrieve and display the full information using the get() methods and display whether this car is worthy purchase via the Decide method

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

class Vehicle{
private:
   string type;
   string name;
   int year;
   double rank;
public:
   Vehicle(){
       type = "default";
       name = "default";
       year = 0;
       rank = 0;
   }
   Vehicle(string t, string n, int y, double r){
       setType(t);
       setName(n);
       setYear(y);
       setRank(r);
   }
   void setType(string t){
       type = t;
   }
   void setName(string n){
       name = n;
   }
   void setYear(int y){
       if(y < 0 || y > 4){
           y = 0;
           cout << "value not legal." << endl;
       }
       else if(y == 1){
           year = 1970;
       }
       else if(y == 2){
           year = 1980;
       }
       else if(y == 3){
           year = 1990;
       }
       else if(y == 4){
           year = 2000;
       }
   }
   void setRank(double r){
       rank = r;
   }
   string getType(){
       return type;
   }
   string getName(){
       return name;
   }
   int getYear(){
       return year;
   }
   double getRank(){
       return rank;
   }
   bool decide(){
       if(year == 2000 && rank >= 3.8){
           return true;
       }
       else{
           return false;
       }
   }
};

int main(){
   Vehicle v1("small", "Ferrari", 4, 3.9);
   Vehicle v2("Medium", "BMW", 3, 3.5);
   cout << "Vehicle 1" << endl;
   cout << "Type: " << v1.getType() << endl;
   cout << "Name: " << v1.getName() << endl;
   cout << "Year: " << v1.getYear() << endl;
   cout << "Rank: " << v1.getRank() << endl;
   if(v1.decide()){
       cout << "It's a worthy purchase" << endl;
   }
   else{
       cout << "It's not a worthy purchase" << endl;
   }
   cout << "Vehicle 2" << endl;
   cout << "Type: " << v2.getType() << endl;
   cout << "Name: " << v2.getName() << endl;
   cout << "Year: " << v2.getYear() << endl;
   cout << "Rank: " << v2.getRank() << endl;
   if(v2.decide()){
       cout << "It's a worthy purchase" << endl;
   }
   else{
       cout << "It's not a worthy purchase" << endl;
   }
   return 0;
}