how do i get my program to run?



Last edited on
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
Here's a start:
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
int main()
{
    struct Auto *head = NULL;
    
    int chassisNum;
    string make;
    string model;
    string type;
    
    ListOfAutos LOA; // <--
    
    int cars{0}; // <--
    
    cout<<"Place the number of Automotives you would like to enter: ";
    cin >> cars;
    
    while(cars > 0) // <--
    {
        cout << "Enter 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;
        cout<<endl;
        
        Autos(chassisNum,make,model,type); // <-- need a non-static object
        // Now find a way to add that car object to the list
        
        cars--;
    }
    
    LOA.Display(head); // <--
    return 0;
}



Place the number of Automotives you would like to enter: 2
Enter the Automotive chasssis-Number: 1
           Enter the Automotive make: 1
          Please enter Vehicle model: 1
               Please enter car type: 1

Enter the Automotive chasssis-Number: 2
           Enter the Automotive make: 2
          Please enter Vehicle model: 2
               Please enter car type: 2

List of Autos(linked list): 
Program ended with exit code: 0
There are multiple issues with the original posted code.

For a starter, consider as 1 file (for ease!):

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();
}

Last edited on
Hi thankyou adding it into one file does make it easier but why when I try to run the program I get no matching constructor for initialization of ListOfAutos?
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
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include<string>
using namespace std;

class Auto
{
public:
    Auto(){};
    Auto(int num, string m, string modl, string typ);
    
    int getChassisNumber();
    string getMake();
    string getModel();
    string getType();
    
    void setChassisNumber(int num );
    void setmake(string m);
    void setModel(string modl);
    void setType(string typ);
    void display();
    
private:
    int chassisNum;
    string make;
    string model;
    string type;
};

Auto::Auto(int num , string m, string modl, string typ)
: chassisNum(11111),make(m),model(modl),type(typ){setChassisNumber(num);}

int Auto::getChassisNumber(){return chassisNum;}
string Auto::getMake(){return make;}
string Auto::getModel(){return model;}
string Auto::getType(){return type;}
void Auto::setChassisNumber(int num){chassisNum = num;}
void Auto::setmake(string m){make = m;}
void Auto::setModel(string modl){model = modl;}
void Auto::setType(string typ) {type = typ;}
void Auto::display()
{cout << chassisNum << '*' << make << '*' << model << '*' << type << '\n';}

struct Node
{
    Auto data;
    Node* next;
};

class ListOfAutos
{
private:
    int count{0};
    Node* head = nullptr;
    Node* tail = nullptr;
    
public:
    ListOfAutos();
    
    void insertAtFront(int, string, string, string);
    void display();
    int size();
};

ListOfAutos::ListOfAutos(){};

void ListOfAutos::insertAtFront( int ch, string mk, string mo, string ty)
{
    Auto au(ch, mk, mo, ty);
    
    Node *tmp = new Node;
    tmp->data = au;
    tmp->next = nullptr;
    
    if(head == nullptr)
    {
        head = tmp;
        tail = tmp;
    }
    else
    {
        tail->next = tmp;
        tail = tail->next;
    }
    count++;
}

void ListOfAutos::display()
{
    Node* temp = head;
    
    while( temp!= tail)
    {
        temp->data.display();
        temp = temp->next;
    }
    temp->data.display();
}

int ListOfAutos::size(){return count;}


int main()
{
    int chassisNum;
    string make;
    string model;
    string type;
    
    int cars{0};
    
    cout<<"Place the number of Automotives you would like to enter: ";
    cin >> cars;
    
    ListOfAutos LOA;
    
    while(cars > 0)
    {
        cout << "Enter 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;
        cout<<endl;
        
        LOA.insertAtFront(chassisNum, make, model, type);
        cars--;
    }
    
    LOA.display();
    cout << LOA.size() << '\n';
    
    return 0;
}



Place the number of Automotives you would like to enter: 3
Enter the Automotive chasssis-Number: 1
           Enter the Automotive make: 1
          Please enter Vehicle model: 1
               Please enter car type: 1

Enter the Automotive chasssis-Number: 2
           Enter the Automotive make: 2
          Please enter Vehicle model: 2
               Please enter car type: 2

Enter the Automotive chasssis-Number: 3
           Enter the Automotive make: 3
          Please enter Vehicle model: 3
               Please enter car type: 3

1*1*1*1
2*2*2*2
3*3*3*3
3
Program ended with exit code: 0
Or to show the autos a bit more meaningfully, and to show where you can update the display format from mine:

Place the number of Automotives you would like to enter: 2
Enter the Automotive chasssis-Number: 123
           Enter the Automotive make: Ford
          Please enter Vehicle model: Ranger
               Please enter car type: Truck

Enter the Automotive chasssis-Number: 4567
           Enter the Automotive make: Honda
          Please enter Vehicle model: Civic
               Please enter car type: Sedan

123*Ford*Ranger*Truck
4567*Honda*Civic*Sedan
2
Program ended with exit code: 0
Hi thankyou adding it into one file does make it easier but why when I try to run the program I get no matching constructor for initialization of ListOfAutos?


It compiled OK with MS VS 2019 (latest updates). Which compiler and C++ version are you using? What's the error message actually saying?
i am using qt 4.7.1 enterprise and this is the exact error code
no matching constructor for initialization of ListOfAutos
qt 4.7.1 was released Nov 2010 and only supports C++98. It is absolutely out of date! You really need to update to qt 6 which supports C++17 or another compiler which supports at least C++17.
Last edited on
@Denvor Please do NOT delete your question after getting your answer. It makes the thread incomprehensible, and useless as a learning resource for others.
Topic archived. No new replies allowed.