Question
C++ Code the car class indicated below: Car //name of class - string model //private member variables - int year - double price + Car()
C++
Code the car class indicated below:
Car //name of class |
- string model //private member variables - int year - double price |
+ Car() //public class functions + Car(string newModel, int newYear, string newColor) + void setPrice(double newPrice) + void setYear(int newYear) + void setModel(int newModel) + double getPrice() const + int getYear() const + string getModel() const + void display() const |
Code the main function:
Write a program for NiftyGMC Dealer, which keeps track of their lot inventory. You may use either a vector of type Car to store all of the Car objects.
Your program will begin with an empty vector, and an empty Car object, and then the user will be allowed to perform any of of the following until he/she wishes to exit:
ADD add a Car to the Car inventory (user provides info on Car)
Code will set the contents of your Car object and push it at the end of the vector
PRINT - print out all Cars stored so far
Code will loop thru the vector .. remember, you can index each vector element
PRICE- accept a price from the user. Print out all Cars that are that price
YEAR ask the user for a year . print out all vehicles that were made that year
EXIT
* THE user will enter their choice (ADD,PRINT,PRICE,YEAR or EXIT) as a C-string. Before trying to identify the users choice, your program should check that the string contains only letters and is all upper case (you have functions to do this from week 10s project).
Week 10's project is completed here: USE THIS IN FINAL PROJECT
#include
using namespace std;
bool AllLetters(char *text)
{
//returns true if all characters are text letters..
int i = 0;
while (text[i] != '\0')//runs upto the end of the string..
{
int c = (int)text[i];
//matching with ascii values..of boundaries of letters
if (c<65)//means not a letter
return false;
else if (c>91 && c<97)//not a letter
return false;
else if (c>123)
return false;
i++;
}
return true;//means all are letters..
}
void AllUpper(char* text) {
//converts all letters to upper case
//accepts only string that contains only letters
if (AllLetters(text))//checking whether it contains all letters or not..
{
int i = 0;
while (text[i] != '\0')
{
int c = (int)text[i];
if (c >= 97 && c <= 123)
{
c = c - 32;//converting to upper
text[i] = (char)c;
}
i++;
}
}
else cout << " Does not contain all letters ";
}
int main()
{
//testing
char c[100];
cout << "Enter a string(without blanks):";
cin >> c;
if (AllLetters(c))cout << " Contains all letters ";
else cout << " Does not contain all letters ";
cout << c << endl;
AllUpper(c);
cout << " Converting to uppercase:" << c << endl;
system("pause");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started