Design a class named Automobile that holds the vehicle identification number, ma
ID: 3696114 • Letter: D
Question
Design a class named Automobile that holds the vehicle identification number, make, model and color of an automobile. Include methods to set the values for each data field, and a method that displays all the values for each. Create the class diagram and write the code in C++, using the following pseudocodes, that define the class.
// Pseudocode PLD Chapter 10 #4 pg. 468
// Start
// Declarations
// Automobile myAuto
// string vin
// string make
// string model
// string color
// output "Please enter the Vehicle Identification Number: "
// input vin
// output "Please enter the Make: "
// input make
// output "Please enter the Model: "
// input model
// output "Please enter the color: "
// input color
// Set the VIN for myAuto
// Set the Make for myAuto
// Set the Model for myAuto
// Set the Color for myAuto
// output "VIN: ", myAuto.getVin()
// output "Make: ", myAuto.getMake()
// output "Model: ", myAuto.getModel()
// output "Color: ", myAuto.getColor()
// Stop
Explanation / Answer
I have executed it under code blocks IDE
main.cpp
#include <cstdlib>
#include <iostream>
#include "AutoMobile.h"
using namespace std;
int main()
{
Automobile a;
//a.read();
a.displayAutomobile();
return 0;
}
void Automobile::read( )
{
cout << "enter vehicle identification number:";
cin >> vin;
setVin(vin); // Vehicle Identification
cout << "enter make number:";
cin >> make;
setMake(make);
cout << "enter model:";
cin >> model;
setModel(model);
cout << "enter color:";
cin >> color;
setModel(color);
}
Automobile::Automobile( )
{
}
void Automobile::setVin(string v)
{
vin = v;
}
void Automobile::setMake(string ma)
{
make = ma;
}
void Automobile::setModel(string mod)
{
model = mod;
}
void Automobile::setColor(string c)
{
color = c;
}
string Automobile::getVin( )
{
return vin;
}
string Automobile::getMake( )
{
return make;
}
string Automobile::getModel( )
{
return model;
}
string Automobile::getColor( )
{
return color;
}
void Automobile::displayAutomobile()
{
Automobile b;
b.read();
cout << "Vehicle Identification Number: " << b.getVin() << endl
<< "Make: " << b.getMake()<< endl
<< "Model: " << b.getModel() << endl
<< "Color: " << b.getColor() << endl;
}
AutoMobiles.h
#include <string>
using namespace std;
#ifndef Automobile_H
#define Automobile_H
class Automobile
{
private:
string vin; // first name
string make; // last name
string model; // subject of the paper
string color; // assigned letter grade
public:
Automobile( );
void setVin(string v);
void setMake(string ma);
void setModel(string mod);
void setColor(string c);
void read( );
string getVin( );
string getMake( );
string getModel( );
string getColor( );
void displayAutomobile();
};
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.