Need to figure out what is wrong with this code

Hi I need a little help with this code that I've been writing for an assignment. This is what I have:
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
 
#include <stdio.h>
#include <iostream>
#include <cmath> 
using namespace std; 

class personalComputer {
private:
    string manufacturer;
    string model;
    string serialNumber;
    string cpu;
    int memory;
    double speed;
    string operatingSystem;
    double diskSize;
    string graphicsCard;
    int usbPortcount;
    int bootState;
public:
    personalComputer(string manufacturer, string model, string serialNumber, string cpu, int memory, double speed, string operatingSystem, double diskSize, string graphicsCard, int usbPortcount, int bootState);
    ~personalComputer();
   
string getManufacturer() const{
    return manufacturer;
    };
string getModel() {
    return model;
};
string getSerial()const {
    return serialNumber;
};
string getCpu()const {
    return cpu;
};
double getSpeed() const{
    return speed;
    };
int getMemory() const{
    return memory;
    };
double getDisksize()const {
    return diskSize;
    };
string getGraphicscard()const {
    return graphicsCard;
    };
int getUsbports() const {
    return usbPortcount;
};
int getBootstate() const {
    return bootState;
};
string getOperating() const {
    return operatingSystem;
};
   
    
    void setManufacturer(string manu) {
        };
    void setModel(string mode) {
    };
    void setSerial(string seri) {
    };
    void setCpu(string cp) {
    };
    void setSpeed(double spee) {
        if (spee >= 0) {
            speed = speed;
        }
        else {
            cout << "Please enter a valid input ( a positive number)." << endl;
            cin >> spee;
        }
    };
    void setMemory(int mem) {
        if (mem >= 1) {
            mem = memory;
        }
        else {
            cout << "Please enter a valid input." << endl;
            cin >> mem;
        }
    };
    void setDisksize(double disk) {
        if (disk >= 1) {
            disk =  diskSize;
        }
        else {
            cout << "Please enter a valid input." << endl;
            cin >> disk;
        }
    };
    void setGraphicscard(string graphics) {
    };
    void setOperating(string op_sy) {
    };
    void setUsbports(int usb) {
        if (usb >=0) {
            usb = usbPortcount;
        }
        else {
            cout << "Please enter a valid input." << endl;
            cin >> usb;
        }
    };
    void setBootstate(int boot) {
        if (boot ) {
            boot = bootState;
        }
        else {
            cout << "Please enter a valid input ( 0 for shut off, 1 for turn on." << endl;
            cin >> boot;
        }
    };


    int main()
    {

        personalComputer comp;
        string manu;
        string mode;
        string seri;
        string cp;
        int mem;
        double spee;
        string op_sy;
        double disk;
        string graphics;
        int usb;
        int boot;
        int spec1;
        int spec2;
        int spec3;


        cout << "This program displays the attributes of a personal computer based on the data you provide.  Please enter the specifications of your computer when prompted. " << endl;
        cout << "Please enter the manufacturer of your computer.";
        cin >> manu;
        cout << endl;
        comp.setManufacturer(manu);

        cout << "Please enter the serial number of your computer.";
        cin >> seri;
        cout << endl;
        comp.setSerial(seri);

        cout << "Please enter the CPU name of your computer.";
        cin >> cp;
        cout << endl;
        comp.setCpu(cp);

        cout << "Please enter the speed of your computer.";
        cin >> spee;
        cout << endl;
        comp.setSpeed(spee);

        cout << "Please enter the memory of your computer.";
        cin >> mem;
        cout << endl;
        comp.setMemory(mem);

        cout << "Please enter the disk size of your computer.";
        cin >> disk;
        cout << endl;
        comp.setDisksize(disk);

        cout << "Please enter the operating system of your computer.";
        cin >> op_sy;
        cout << endl;
        comp.setOperating(op_sy);

        cout << "Please enter the number of USB ports on your computer.";
        cin >> usb;
        cout << endl;
        comp.setUsbports(usb);

        cout << "Please enter the graphics card of your computer.";
        cin >> graphics;
        cout << endl;
        comp.setGraphicscard(graphics);




 
  
    return 0;}};


I have a couple more sections to add on this, but I keep on getting error messages for part of it. I'm not really sure what I'm not really sure what I'm doing wrong when I try to fix it, because the error code keeps changing.

Here is the error log for this from c++ shell
In member function 'int personalComputer::main()':
125:26: error: no matching function for call to 'personalComputer::personalComputer()'
125:26: note: candidates are:
25:5: note: personalComputer::personalComputer(std::string, std::string, std::string, std::string, int, double, std::string, double, std::string, int, int)
25:5: note: candidate expects 11 arguments, 0 provided
11:7: note: personalComputer::personalComputer(const personalComputer&)
11:7: note: candidate expects 1 argument, 0 provided
206:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
136:13: warning: unused variable 'boot' [-Wunused-variable]
139:13: warning: unused variable 'spec3' [-Wunused-variable]

I'm not sure what I"m doing wrong on the personalComputer section.
Last edited on
Please edit your code and add [code] and [/code] around your code to format your code.

The problem is that you only have 1 constructor defined for your personalComputer class.
1
2
3
personalComputer(string manufacturer, string model, string serialNumber,
    string cpu, int memory, double speed, string operatingSystem,
    double diskSize, string graphicsCard, int usbPortcount, int bootState);


When you define a custom constructor instead of using the default constructor, it is automatically removed unless you explicitly make another, 0-arg constructor yourself.

You don't use this multi-arg constructor that you defined, so the easiest thing would be to remove it.

______________________________

1
2
3
if (spee >= 0) {
speed = speed;
}

What is the purpose of this? speed = speed is essentially a no-op.
Last edited on
Also, for the coding pros out there, I'm sorry if this is something super easy that I overlooked. I'm still not the most comfortable programming and I'm not understanding where I'm messing things up at. I tried to switch the personalComputer ( with variables) to

personalComputer::personalComputer(with variables)
but an error for it still pops up.
Last edited on
I assumed at first that you simply left it out, but if that's your full code, the issue is that you declare your constructor, but don't define it. However, the code you posted now does not match the line numbers that the compiler is printing.

Still, the solution is the same. You are not using that multi-arg constructor, so just delete line 21 (and 22).
Last edited on
Sorry about not formatting it properly. Thanks for letting me know.
Also oops that a type-o on the speed sections it should've been spee=speed, so that it can change the private members of the class.
Thanks for you help! I really appreciate it.
Last edited on
You also should adopt more consistent indentation.

Part of your issue is that you are defining main within your class. Your main function should be outside of the class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class MyClass {
private:
    // ...

public:
    void some_functions()
    {
        // ...
    }
};

int main()
{
    MyClass myclass;
}

Last edited on
Thank you for the knowledge Ganado! I definitely need to work on indenting more consistently. Sorry that I made if so difficult to read. Also thank you so much once again! I would've spent a long time trying to figure out what I was doing wrong and you figure it out in a minute.
Topic archived. No new replies allowed.