1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <string>
using namespace std;
class Autos {
public:
Autos(int num, const string& m, const string& modl, const string& typ);
int getChassisNumber() const;
string getMake() const;
string getModel() const;
string getType() const;
void setChassisNumber(int num);
void setmake(const string& m);
void setModel(const string& modl);
void setType(const string& typ);
private:
int chassisNum {};
string make;
string model;
string type;
};
Autos::Autos(int num, const string& m, const string& modl, const string& typ) : chassisNum(num), make(m), model(modl), type(typ) {}
int Autos::getChassisNumber() const { return chassisNum; }
string Autos::getMake() const { return make; }
string Autos::getModel() const { return model; }
string Autos::getType() const { return type; }
void Autos::setChassisNumber(int num) { chassisNum = num; }
void Autos::setmake(const string& m) { make = m; }
void Autos::setModel(const string& modl) { model = modl; }
void Autos::setType(const string& typ) { type = typ; }
class ListOfAutos {
public:
ListOfAutos() {}
~ListOfAutos();
ListOfAutos(const ListOfAutos&) = delete;
ListOfAutos& operator=(const ListOfAutos&) = delete;
void insertAtFront(int num, const string& m, const string& modl, const string& typ);
void Display() const;
void CountList() const;
private:
struct Node {
Autos aut;
Node* next {};
};
Node* head {};
};
ListOfAutos::~ListOfAutos() {
while (head) {
const auto cur {head};
head = head->next;
delete cur;
}
}
void ListOfAutos::insertAtFront(int num, const string& m, const string& modl, const string& typ) {
head = new Node({num, m, modl, typ}, head);
}
void ListOfAutos::Display() const {
int i {1};
cout << "List of Autos (linked list):\n";
for (auto cur = head; cur; cur = cur->next, ++i) {
cout << "+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+\n";
cout << "+_Auto: " << i << '\n';
cout << "+_Chassis number: " << cur->aut.getChassisNumber() << '\n';
cout << "+_Make : " << cur->aut.getMake() << '\n';
cout << "+_Model: " << cur->aut.getModel() << '\n';
cout << "+_Type: " << cur->aut.getType() << '\n';
cout << "+_+++++++++++++++++++++++++++++++++++++++-+\n";
}
std::cout << "\n\n";
}
void ListOfAutos::CountList() const {
int counter {};
for (auto cur = head; cur; cur = cur->next)
++counter;
cout << "\n+_+++++++++++++++++++++++++++++++++++++++-+\n";
cout << "+_There are: " << counter << " automotives in the list_+\n";
cout << "+_+++++++++++++++++++++++++++++++++++++++-+\n\n\n";
}
int main() {
ListOfAutos loa;
int chassisNum {};
string make;
string model;
string type;
int cars {};
cout << "How many Automotives would you like to enter: ";
cin >> cars;
while (cars-- > 0) {
cout << "\nEnter the Automotive chasssis-Number: ";
cin >> chassisNum;
cout << "Enter the Automotive make : ";
cin >> make;
cout << "Please enter Vehicle model : ";
cin >> model;
cout << "Please enter car type : ";
cin >> type;
loa.insertAtFront(chassisNum, make, model, type);
}
loa.CountList();
loa.Display();
}
| |