Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int idgen = 0;
- class Car{
- private:
- int id;
- string manufacturer;
- float mileage;
- string color;
- Car *next;
- public:
- Car(): id(++idgen), manufacturer("N/A"), mileage(0.0), color("N/A"), next(NULL) {}
- Car(string menf, float mlg, string clr): id(++idgen), manufacturer(menf), mileage(mlg), color(clr), next(NULL) {}
- ~Car() {}
- void show() {
- cout << left << setw(15) << "ID " << ": " << left << id << endl;
- cout << left << setw(15) << "Manufacturer " << ": " << left << manufacturer << endl;
- cout << left << setw(15) << "Color " << ": " << left << color << endl;
- cout << left << setw(15) << "Mileage " << ": " << left << mileage << endl << endl;
- }
- void read(){
- cout << "Enter info for Car " << id << endl;
- cout << "Enter Manufacturer: ";
- cin >> manufacturer;
- cout << "Enter Color: ";
- cin >> color;
- cout << "Enter Mileage: ";
- cin >> mileage;
- }
- string getMan() { return manufacturer;}
- string getColor() { return color;}
- float getMile() { return mileage;}
- void setNext(Car *C) { next = C;}
- Car * getNext() { return next;}
- void setMile(float m) { mileage = m;}
- };
- void showToyota(Car *C){
- Car *Current;
- for(Current = C; Current != NULL; Current = Current -> getNext())
- if(Current -> getMan() == "Toyota" || Current -> getMan() == "toyota")
- Current -> show();
- }
- void showRed(Car *C){
- Car *Current;
- for(Current = C; Current != NULL; Current = Current -> getNext())
- if(Current -> getColor() == "Red" ||Current -> getColor() == "red")
- Current -> show();
- }
- void show25(Car *C){
- Car *Current;
- for(Current = C; Current != NULL; Current = Current -> getNext())
- if(Current -> getMile() >= 25.0)
- Current -> show();
- }
- void setToyota(Car *C){
- Car *Current;
- for(Current = C; Current != NULL; Current = Current -> getNext())
- if(Current -> getMan() == "Toyota" || Current -> getMan() == "toyota"){
- Current -> setMile(40.0);
- Current -> show();
- }
- }
- int main(){
- Car *Front = new Car();
- Car *Current;
- Car *Last;
- Current = Front;
- while(true) {
- Last = Current;
- Current -> read();
- char cont;
- cout << "Do you want to continue (y/n)? ";
- cin >> cont;
- if(cont == 'n' || cont == 'N') break;
- Current = new Car();
- Last -> setNext(Current);
- }
- cout << endl << endl << "PRINTING ALL" << endl;
- for(Current = Front; Current != NULL; Current = Current -> getNext())
- Current -> show();
- cout << endl << endl << "PRINTING ALL TOYOTA" << endl;
- showToyota(Front);
- cout << endl << endl << "PRINTING ALL RED" << endl;
- showRed(Front);
- cout << endl << endl << "PRINTING ALL 25+" << endl;
- show25(Front);
- cout << endl << endl << "setting All TOYOTA 40" << endl;
- setToyota(Front);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement