(C++)This is the problem that I'm supposed to write a program for:
This is the layout that we are supposed to fill out for the
project:
If anything is unclear, comment and I'll try to
clarify. Thank you!
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
(C++)This is the problem that I'm supposed to write a program for: This is the layout...
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 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 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 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 (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 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 : 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 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 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 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. -...