Question

(C++)This is the problem that I'm supposed to write a program for:

Objective Reading Dala Files Project This is a variation of ng challenge 133 de Write a class named Car that has the following pelvate member variables. model Year An ie cars uodd year. make A string that bolds the make of the car speed A olds the cars current speed. In addition, the class should have the following constructor and other mem- ber functions. Constructor The constructor should aropt the cars model year snell make as arguments. These values should be assigned to the objects model Year and make member variables. The constructor should assign the value 0 to the speed member variable. getModelYear An aceessor that returns the cars model year get Make An accessor that returns the cars make getSpeed An arressar that returns the cars pred accelerate A mutator that adds five to the speed member variable. brake A mutator that subtracts five from the speed member variable unless the value in speed is zero ut kss. Demonstrate the class in a program that creates a Car object. It then enters a loop that prompts the user if they want to accelerate, brake, or quit. Each tinue it prints the current speed af the car. Submission Name your script file project -13-abc-epp where abe are your ni tials. Submit your source oode (the file that ends in .epp) to the elass folder on Box 11:59 pen om Wednesday, April 26, 2016. by


This is the layout that we are supposed to fill out for the project:

media%2F9d8%2F9d8fea48-6c00-42f3-9a68-73

media%2Fc63%2Fc63ef709-8e11-4bed-8bee-04

media%2F239%2F239a3e5e-e7c4-411c-99b3-be

If anything is unclear, comment and I'll try to clarify. Thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The CPP File:project_13_SSG.cpp

-----------------------------------------------------------

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

//class defination
class Car
   {
       private:
           int year;
           string make;
           int speed;
       public:
       Car();
       Car(int y,string m);
       const int getModelYear();
       const string getMake();
       const int getSpeed();
       void accelerate();
       void brake();  
   };


//funvction prototype
const void printHeader(string,string,string,string);
void drive(Car &);
const void printResult(Car & );

//class method definations
   Car::Car()
       {
           year=1972;
           make="Ford Pinto";
           speed=0;
       }
   Car::Car(int y,string m)
       {
           year=y;
           make=m;
           speed=0;
       }

  
   const int Car::getModelYear()
       {
       return year;
       }
   const string Car::getMake()
       {
       return make;  
       }
      
   const int Car::getSpeed()
       {
       return speed;
       }
   void Car::accelerate()
       {
       speed=speed+5;
       }
   void Car::brake()
       {
           speed=speed-5;
       }

//main fiucntion
int main(void)
   {
   //Call the Function to print header
   printHeader("SSG","CMPSC 121","21-April-2017","The Program displays the status of a car");
  
   //Create Car object
   Car myCar;
  
   //call this function to start driving loop
   drive(myCar);
  
      
   }

  
   //This function starts a whilre loop and the user choose an option
   // to accelerate,brake or quit
   void drive(Car &carData)
       {
       int choice;
       while(true)  
           {
           cout<<endl<<endl;
           cout<<endl<<"1: Accelerate";
           cout<<endl<<"2: Brake";
           cout<<endl<<"3: Quit";
           cout<<endl<<"Enter choice(1,2,3): ";
           cin>>choice;
           switch(choice)
               {
               case 1:
                   carData.accelerate();
                   printResult(carData);
                   break;
               case 2:
                   carData.brake();
                   printResult(carData);
                   break;
               case 3:
                   exit(0);
               }
           }
       }
const void printHeader(string name,string course,string duedate,string description)
   {
       //printthe header .Informationsa are passed from main ()
       cout<<endl;
       cout<<name<<endl;
       cout<<course<<endl;
       cout<<duedate<<endl;
       cout<<description<<endl;
       getchar();
       cout<<string(22,'\n');
       return;
   }

const void printResult(Car &carData)
       {
       //printResult() displays the status of the car
       cout<<endl<<"Current status:";
       cout<<endl<<"Model :"<<carData.getModelYear();
       cout<<endl<<"Make :"<<carData.getMake();
       cout<<endl<<"Speed :"<<carData.getSpeed();
       return;
       }

//------------------------------------------------------------

output

CATurboC++\Diskt TurboC3\ BINCarTest.exe SSG 21-April-201? HPSC 11-2017 The Program displays the status of a car

Add a comment
Know the answer?
Add Answer to:
(C++)This is the problem that I'm supposed to write a program for: This is the layout...
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
  • Car Class Background: Write a class named Car that will be used to store information and...

    Car Class Background: Write a class named Car that will be used to store information and control the acceleration and brake of a car. Functionality: 1. Write a class named "Car” that has the following member variables: • year Model - an int that holds the car's year model • make-A string that holds the make of the car • speed - an int that holds the car's current speed 2. In addition the class should have the following member...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    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...

  • java Write a class named Car that has the following fields: • yearModel: The yearModel field...

    java Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values...

  • python Design a class named Car that has the following fields: yearModel: The yearModel field is...

    python Design a class named Car that has the following fields: yearModel: The yearModel field is an Integer that holds the car’s year model. make: The make field references a String that holds the make of the car. speed: The speed field is an Integer that holds the car’s current speed. In addition, the class should have the following constructor and other methods: Constructor: The constructor should accept the car’s year model and make as arguments. These values should be...

  • In Python Programming: Write a class named Car that has the following data attributes: _ _year_model...

    In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...

  • Lab 10C - Creating a new class This assignment assumes that you have read and understood...

    Lab 10C - Creating a new class This assignment assumes that you have read and understood the following documents: http://www.annedawson.net/Python3_Intro_OOP.pdf http://www.annedawson.net/Python3_Prog_OOP.pdf and that you're familiar with the following example programs: http://www.annedawson.net/python3programs.html 13-01.py, 13-02.py, 13-03.py, 13-04.py Instructions: Complete as much as you can in the time allowed. Write a Python class named "Car" that has the following data attributes (please create your own variable names for these attributes using the recommended naming conventions): - year (for the car's year of manufacture)...

  • Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year :...

    Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year : int ----------------------- + Car() + setMake(m: string) : void + getMake() : string + setYear(y: int) : void + getYear() : int ---------------------- */ #ifndef CAR_H #define CAR_H #include <iostream> using namespace std; class Car { private: string make; int year; public: Car(); Car(string); Car(int); Car(string, int); void setMake (string); string getMake() {return make;} void setYear (int); int getYear() {return year;} }; #endif #include...

  • Java Program Write a class named Car that has the following fields: yearModel- The yearModel field...

    Java Program Write a class named Car that has the following fields: yearModel- The yearModel field is an int that holds the car’s year model. make- The make field is a String object that holds the make of the car, such as “Ford”, “Chevrolet”, etc. speed- This speed field is an int that holds the car’s current speed. In addition, the class should have the following methods: Constructor- The constructor should accept the car’s year model and make as arguments....

  • Write a java program that creates a class Car. Class Car contains the following private member...

    Write a java program that creates a class Car. Class Car contains the following private member fields: make, model, year, and miles. The class Car has a constructor that takes as arguments the car make, model, and year. In addition, the constructor sets miles to 100 as default. Class Car has accessors and mutators to get and set the make, model, year and miles on the car. The program should complete the following tasks: Ask the user to enter make,...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

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
ADVERTISEMENT