expression must have class type, not sure what to do to change it properly

Hi could someone please look over this code? I'm not sure what I need to change on my code to get rid of the above error message. I have a header file and 2 cpp files that are ok, but the main file keeps giving me this error message.
Main file

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
191
192
193
194
195
196
 #include <iostream>
#include <string>
#include "Header.h"
using std::string;
using namespace std;
/*
//get string function
void getString(string& in, string pr) {
	std::cout << pr;
	std::cin >> in;
	getline(std::cin, in);
	std::cin.ignore(50, '\n');
}
//get int function
void getNumber(int& in, string pr) {
	std::cout << pr;
	if (!(std::cin >> in)) {
		std::cin.clear();
		std::cin.ignore(50, '\n');
		getNumber(in, pr);
	}
}
//get double function
void getDouble(double& in, string pr) {
	std::cout << pr;
	if (!(std::cin >> in)) {
		std::cin.clear();
		std::cin.ignore(50, '\n');
		getDouble(in, pr);
	}
}
*/

int main(){

    personal_computer comp(string manu, string mode, string seri, string cp, int mem, double spee, string opsy, int diskSize, string graphics, int usbPortcount);
    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();

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




    cout << "************************************************" << endl;
    cout << "The specifications of the computer you entered are:" << endl;
    cout << "Manufacturer:      " << comp.getManufacturer() << endl;
    cout << "Operating System:  " << comp.getOperating() << endl;
    cout << "CPU:               " << comp.getSerial() << endl;
    cout << "Disk Size:         " << comp.getDisksize() << endl;
    cout << "Memory:            " << comp.getMemory() << " GB" << endl;
    cout << "Speed:             " << comp.getSpeed() << " GHz" << endl;
    cout << "Memory:           " << comp.getMemory() << endl;
    cout << "Graphics Card:    " << comp.getGraphicscard() << endl;
    cout << "USB ports:        " << comp.getUsbports() << endl;
    cout << "************************************************" << endl;

    cout << "Would you like to change any of the specifications lister? Press 1 for yes or 0 for no.";
    cin >> spec1;
    if ((spec1 == 0)) {
        cout << "Would you like to turn off/change the boot state of this computer?";
    }
    if ((spec1 == 1)) {
        cout << "Please select which specification you would like to change ( Enter the number listed for the specification you would like to change): " << endl;
        cout << " 1 - Manufacturer" << endl;
        cout << " 2 - Serial Number " << endl;
        cout << " 3 - Operating System  " << endl;
        cout << " 4 - CPU              " << endl;
        cout << " 5 - Disk Size         " << endl;
        cout << " 6 - Memory            " << endl;
        cout << " 7 - Speed             " << endl;
        cout << " 8 - Graphics Card    " << endl;
        cout << " 9 - USB ports      " << endl;
        cin >> spec2;
    };

    if ((spec2 == 1)) {
        cout << "Please enter the new name of the manufacturer you would like to enter for your compunter:";
        cin >> manu;
        cout << endl;
        comp.setManufacturer(manu);
    }
    else if ((spec2 == 2)) {
        cout << "Please enter the new serial number for your computer.";
        cin >> seri;
        cout << endl;
        comp.setSerial(seri);
    }
    else if ((spec2 == 3)) {
        cout << "Please enter the operating system of your computer.";
        cin >> op_sy;
        cout << endl;
        comp.setOperating(op_sy);
    }
    else if ((spec2 == 4)) {
        cout << "Please enter the CPU of your computer.";
        cin >> cp;
        cout << endl;
        comp.setCpu(cp);
    }
    else if ((spec2 == 5)) {
        cout << "Please enter the disk size of your computer.";
        cin >> disk;
        cout << endl;
        comp.setDisksize(disk);
    }

    else if ((spec2 == 6)) {
        cout << "Please enter the memory of your computer.";
        cin >> mem;
        cout << endl;
        comp.setMemory(mem);
    }
    else if ((spec2 == 7)) {
        cout << "Please enter the speed of your computer.";
        cin >> spee;
        cout << endl;
        comp.setSpeed(spee);
    }
    else if ((spec2 == 8)) {
        cout << "Please enter the name of your graphics card for your computer.";
        cin >> graphics;
        cout << endl;
        comp.setGraphicscard(graphics);
    }

    else if ((spec2 == 9)) {
        cout << "Please enter the number of USB ports on your computer.";
        cin >> usb;
        cout << endl;
        comp.setUsbports(usb);
    }
    else {
        cout << "Please enter a valid input." << endl;
        cin >> op_sy;
    };


    return 0;
}
Last edited on
Header file and other cpp
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

#pragma once
#include <iostream>
#include <string>
using std::string;


class personal_computer {
private:
	std::string manufacturer;
	std::string model;
	std::string cpu;
	std::string serialNumber;
	int memory;
	double speed;
	std::string operatingSystem;
	std::string diskSize;
	bool bootState;
	int usbPortcount;std::
    string graphicsCard;
//  other attribute

public:
    personal_computer(string manu, string mode, string cp, string seri, double spee, int mem, string op_sy, int disk, int usb);
    ////////////////////////////////////ACCESSORS////////////////////////////////////
    std::string getManufacturer();
    std::string getModel();
    std::string getSerial();
    std::string getCpu();
    double getSpeed();
    int getMemory();
    std::string getDisksize();
    std::string getGraphicscard();
    int getUsbports();
    int getBootstate();
    std::string getOperating();
    ////////////////////////////////////MUTATORS////////////////////////////////////
    void bootup();
    void shutdown();
    void restart();
    void setManufacturer(std::string manu);
    void setModel(std::string mode);
    void setSerial(std::string seri);
    void setCpu(std::string cp);
    void setSpeed(double spee);
    void setMemory(int mem);
    void setDisksize(std::string disk);
    void setGraphicscard(std::string graphics);
    void setOperating(std::string op_sy);
    void setUsbports(int usb);
    };




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

#include <iostream>
#include <string>
#include "Header.h"
using std::string;


   personal_computer::personal_computer(string manu,string mode, string cp, string seri, double spee, int mem, string op_sy, int disk, int usb) {
        manufacturer = manu;
        model = mode;
        cpu = cp;
        serialNumber = seri;
        operatingSystem = "n/a";
        memory = 0;
        speed = 0;
        diskSize = "n/a";
        bootState = true;
        usbPortcount = 0;
    }

    ////////////////////////////////////ACCESSORS////////////////////////////////////

    string personal_computer::getManufacturer() {
        return manufacturer;
    }
    string personal_computer::getModel() {
        return model;
    }
    string personal_computer::getSerial() {
        return serialNumber;
    }
    string personal_computer::getCpu() {
        return cpu;
    }
    double personal_computer::getSpeed() {
        return speed;
    }
    int personal_computer::getMemory() {
        return memory;
    }
    string personal_computer::getDisksize() {
        return diskSize;
    }
    string personal_computer::getGraphicscard() {
        return graphicsCard;
    }
    int personal_computer::getUsbports() {
        return usbPortcount;
    }
    int personal_computer::getBootstate() {
        return bootState;
    }
    string personal_computer::getOperating() {
        return operatingSystem;
    }


    ////////////////////////////////////MUTATORS////////////////////////////////////

    void personal_computer::bootup() {
        if (bootState == true) {
            throw std::runtime_error("The computer is already on.");
        }
        bootState = true;
    }


    void personal_computer::shutdown() {
        if (bootState == false) {
            throw std::runtime_error("The computer is already off.");
        }
        bootState = false;
    }

    void personal_computer::restart() {
        std::cout << "Computer is restarting.";
        shutdown();
        bootup();
    }


    void personal_computer::setManufacturer(string manu) {
        if (manu.length() < 2) {
            throw std::invalid_argument("Manufacturer not provided. The name length of the manufacturer needs to be larger than 2 characters.");
        }
        manu = manufacturer;
    }
    void personal_computer::setModel(string mode) {
        if (mode.length() < 2) {
            throw std::invalid_argument("Model not provided. The name length of the model needs to be larger than 2 characters.");
        }
        mode = model;
    }
    void personal_computer::setSerial(string seri) {
        if (seri.length() < 3) {
            throw std::invalid_argument("Serial number not provided. The name length of the serial number needs to be larger than 3 characters.");
        }
        seri = serialNumber;
    }
    void personal_computer::setCpu(string cp) {
        if (cp.length() < 2) {
            throw std::invalid_argument("The name length of the cpu needs to be larger than 2 characters.");
        }

        cp = cpu;
    }
    void personal_computer::setSpeed(double spee) {
        if (spee >= 33) {
            spee = speed;
        }
        else {
            throw std::invalid_argument("Speed must be greater than 33.");
        }
    }
    void personal_computer::setMemory(int mem) {
        if (mem == 2 || mem == 4 || mem == 8 || mem == 16 || mem == 32 || mem == 64 || mem == 128) {
            mem = memory;
        }
        else {
            throw std::invalid_argument("Memory must be a power of 2. ( 2, 4, 8, 16, 32, 64, or 128)");
        }
    }

    void personal_computer::setDisksize(string disk) {
        if (disk == "250GB" || disk == "480GB" || disk == "1TB" || disk == "2TB" || disk == "4TB" || disk == "8TB" || disk == "12TB") {
            disk = diskSize;
        }
        else {
            throw std::invalid_argument("Disk size must be one of the following 250GB, 500GB, 1TB, 2TB, 4TB, 8TB, 12TB.(Please enter GB or TB in capital letters and with no spaces.)");
        }
    }
    void personal_computer::setGraphicscard(string graphics) {
        if (graphics.length() < 2) {
            throw std::invalid_argument("The name length of the graphics card needs to be larger than 2 characters.");
        }
        graphics = graphicsCard;
    }
    void personal_computer::setOperating(string op_sy) {
        if (op_sy.length() < 2) {
            throw std::invalid_argument("The name length of the operating system needs to be larger than 2 characters.");
        }
        op_sy = operatingSystem;
    }
    void personal_computer::setUsbports(int usb) {
        if (usb < 0) {
            throw std::invalid_argument("The number of usb ports cannot be less than 0.");
        }
        usb = usbPortcount;

    }
Last edited on
Sorry for how long it is
hello kg88,

You could start by posting the complete error message.

As it is I have no idea where to look for an error.

And just in case if the program requires reading an input file(s). Post the file(s) or at least t good sample.

Andy
Hi Andy! Thanks for the response!
Here's is the error file. I think that if one section is fixed, it should fix most if not all of it. I'm just not sure what I missed. The first post is the code for main.cpp
main.cpp is linked to header.h ( the 2nd set of code used) and the 3rd set of code are the functions for the code in another cpp file.
Please let me know if there is anything else that I need to post to help with figuring it out.
Thanks again!

Severity Code Description Project File Line Suppression StateError (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 56

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 61

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 66

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 71

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 76

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 81

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 86

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 91

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 96

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 103

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 104

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 105

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 106

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 107

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 108

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 109

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 110

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 111

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 137

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 143

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 149

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 155

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 161

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 168

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 174

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 180

Error (active) E0153 expression must have class type Project1 C:\Users\earth\source\repos\Project1\Project1\main.cpp 187
Last edited on
The infamous C++'s most vexing parse:
If something could declare a function, then it declares a function.
1
2
3
4
5
6
7
8
9
10
11
int main()
{
  personal_computer comp( string manu, string mode, string seri, string cp,
              int mem, double spee, string opsy, int diskSize, string graphics,
              int usbPortcount );
  string manu;
  string mode;
  // ...
  cin >> manu;
  cout << endl;
  comp.setManufacturer();

This is declaration of function "comp" that returns value of type "personal_computer" (and takes many parameters):
1
2
3
  personal_computer comp( string manu, string mode, string seri, string cp,
              int mem, double spee, string opsy, int diskSize, string graphics,
              int usbPortcount );

Since comp is a function, then it cannot be a class object.

If you want to create an object, then do so:
1
2
3
personal_computer comp;

comp.setManufacturer( "ACME" );

It would be nice if you have all the data to initialize the object during declaration:
personal_computer comp( "ACME", ... );
Last edited on
Thank you so much keskiverto! I was playing around with my code trying to figure out what I did wrong, but then decided to ask before I mess up the other parts. I was finally able to get it running properly. Thanks again!
Hello kg88,

Actually the first error is not on line 56 it starts back on line 36.

You are trying to create an object of the class with an overloaded ctor using variables that have yet to be defined. When I ddefined a default ctor in the header file and wrote: personal_computer comp;. the first error on line 56 went away and a new one came up.

The way your code is written all you need is an object of the class using the default ctor to construct it. Later you use the "set" functions on the class.

The new error on line 56 is that you are calling the set function, but not sending it anything to use.

Later you define in "main": double disk;, but when you call the set function it is expecting a "std::string". The types do not match and the is no built in way to convert a "double" to a "std::string" unless you want to use a string stream, but that is more work than you need.

While I am thinking about in both the ".cpp" you have: using std::string;, but in some places you do write "std::string" and in other places just "string". You are half way there. Loose the using statement and just get use to putting "std::" in front of "string". Also loose the line: using namespace std; and put "std::" in front of what is needed like; "cout", "cin", "getline" and the others. IMHO I feel that it is better to learn a little at a time than everything at once.

Prefer using (\n) over "endl" whenever you can. "endl" is a function that takes time to call and process. The updates to the standards have allowed the new line (\n) to empty the buffer when encountered.

As a suggestion:
1
2
3
4
5
6
7
8
9
10
11
12
13
cout <<
    "************************************************\n"
    "The specifications of the computer you entered are:\n"
    "Manufacturer:      " << comp.getManufacturer() << "\n"
    "Operating System:  " << comp.getOperating() << "\n"
    "CPU:               " << comp.getSerial() << "\n"
    "Disk Size:         " << comp.getDisksize() << "\n"
    "Memory:            " << comp.getMemory() << " GB\n"
    "Speed:             " << comp.getSpeed() << " GHz\n"
    "Memory:           " << comp.getMemory() << "\n"
    "Graphics Card:    " << comp.getGraphicscard() << "\n"
    "USB ports:        " << comp.getUsbports() << "\n"
    "************************************************\n";

There is no need for a "cout" statement for every line. Between what is in double quotes and the insertion operator, (<<), you can chain everything together in 1 "cout" statement. Lines 2 and 3 become just 1 string. The end of 4 and the beginning of 5 become 1 string. Also since everything lines up better you can see that lines 10, 11, and 12 are 1 space short even before you see it on the screen.

And when you get to this part of the code:
1
2
3
4
5
6
7
8
9
10
11
cout << 
    " 1 - Manufacturer\n"
    " 2 - Serial Number\n"
    " 3 - Operating System\n"
    " 4 - CPU              \n"
    " 5 - Disk Size         \n"
    " 6 - Memory            \n"
    " 7 - Speed             \n"
    " 8 - Graphics Card    \n"
    " 9 - USB ports      ";
cin >> spec2;

First from line 5 on the extra spaces do not really do anything. B4 the (;) on line 10 you can press enter and easily add: " Enter choice: ". Also what works to your advantage is the "cin" on the last line. This will flush the output buffer B4 any input is allowed, so the use of "endl" or even a new line is not needed.

Since I have not fixed all the errors yet I have not tried to run the program.

Andy
Thanks Andy! I wish I could learn a little at a time, but my computer science class is moving so fast. I think it would be much better too. I took a crash course last summer in computer science 1 and am still feeling the effects in computer science 2 from not solidly learning the material and also from having to cram so much. I don't know why in class we always use the namespace section.
This is some code that I made about a month ago and we have to keep on going back and editing it for class. That's probably why I keep switching between std::string and string ( I found out that std:: is better a couple of weeks ago, but there are remnants of my old code there that I have to correct). I didn't realize the difference between \n and endl; and that it takes more time.
I think as I learn a little bit more about the underlying reasons behind doing certain things, then it makes sense, but if I don't quite understand it, then I'm just stuck making guesses (hopefully educated).
Thanks you so much for your advice and your knowledge!
Hello kg88,

I can understand about the fast paced class, but that is even more reason to work at it now rather than later. It also gives you time to understand the error messages you will get.

I don't know why in class we always use the namespace section.


I have come to the conclusion that teaching about name spaces is left for later to see who sticks with the classes or maybe it was designed that way to get more money out of you. Just some thoughts.

Since you are working on old code it is good it is good practice to qualify what is in the standard name space.

I have been working on your program and found that most input to "std::string"s would work better using "std::getline()". Several of the strings are likely to have 1 or more spaces in them and using formatted input: std::cin >> manu with an input of (Apple Inc.) would put "Apple" into "manu" and "Inc." into "seri" not giving you a chance to enter a serial number. And a name like "Hon Hai Precision Industry Co. Ltd." /would really make a mess out of the following inputs especially when you get to a numeric input.

One advantage to using "std::getline" is if you happen to enter "1 TB" it is not a problem.

After the last numeric and B4the next "std::getline" you will need "std::cin.ignore();" to clear the "\n" from the input buffer.

This is what I did with the code:
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
cout << " Please enter the manufacturer of your computer: ";
std::getline(std::cin, manu);

comp.setManufacturer(manu);

cout << "\n Please enter the serial number of your computer.: ";
std::getline(std::cin, seri);

comp.setSerial(seri);

cout << "\n Please enter the CPU name of your computer.: ";
std::getline(std::cin, cp);

comp.setCpu(cp);

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

cout << "\n Please enter the memory of your computer. ( 2, 4, 8, 16, 32, 64, or 128): ";
cin >> mem;

comp.setMemory(mem);

std::cin.ignore();

cout << "\n Please enter the disk size of your computer. (250GB, 500GB, 1TB, 2TB, 4TB, 8TB, 12TB): ";
std::getline(std::cin, disk);

comp.setDisksize(disk);

cout << "\n Please enter the operating system of your computer.: ";
std::getline(std::cin, op_sy);

comp.setOperating(op_sy);

cout << "\n Please enter the number of USB ports on your computer.: ";
cin >> usb;

std::cin.ignore();

comp.setUsbports(usb);

cout << "\n Please enter the graphics card of your computer.: ";
std::getline(std::cin, graphics);

comp.setGraphicscard(graphics);

Once it was working I put a comment on all those lines.

I changed this line at the beginning of "main":
1
2
//personal_computer comp();
personal_computer comp("Me",  "1234", "Core I5", 128, 1000000, "Windozzzze 10", "1TB", "Graphics Card", 4);

Then adjusted the header file and the ".cpp" file to match.

Notice how I changed the prompts on line 21 and 28. First time I ran the program I had no idea what to enter.

This way once the section for input is working you can you can skip this section and use the overloaded ctor to set up the class and concentrate on what comes next.

When you are ready just reverse the comments on the above 2 lines and uncomment the input section. It saves time of having to enter something each time the program runs.

I did manage to get this far, minus the input section:

 This program displays the attributes of a personal computer based on the data you provide.
 Please enter the specifications of your computer when prompted.


 ************************************************
 The specifications of the computer you entered are:
 Manufacturer:      Me
 Serial Number:     1234
 Operating System:  Windozzzze 10
 CPU:               Core I5
 Disk Size:         1TB
 Memory:            128 GB
 Speed:             2.50 GHz
 Graphics Card:    Graphics Card
 USB ports:        4
 ************************************************

 Would you like to change any of the specifications lister?
 1 for yes
 0 for no.
  Enter choice: 1

 Please select which specification you would like to change
 (Enter the number listed for the specification you would like to change):

 1 - Manufacturer
 2 - Serial Number
 3 - Operating System
 4 - CPU
 5 - Disk Size
 6 - Memory
 7 - Speed
 8 - Graphics Card
 9 - USB ports
  Enter choice:


One place I did notice a problem is void personal_computer::setSpeed. If you would want tp output "2.50GHz" you would have to enter the number "2'500'000" then I divided that by "1'000'000" to get the "2.50" in the output.

In the set function change ">= 33" to "> 0" then the user could enter "2.5" and it would not be a problem. If (0) zero or a negative number is entered then the else statement would be executed.

Just some things I saw that you may want to consider.

Andy
Hello kg88,

Something else I did in the header file:
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
#ifndef HEADER_H
#define HEADER_H

#include <iostream>
#include <string>

//using std::string;

class personal_computer
{
    private:  // <--- This section is private by defaule.
        std::string manufacturer;
        std::string model;
        std::string cpu;
        std::string serialNumber;
        int memory{};
        double speed{};
        std::string operatingSystem;
        std::string diskSize;
        bool bootState{};
        int usbPortcount{};
        std::string graphicsCard;
        //  other attribute

    public:
        personal_computer() {}
        //("Me",  "1234", "Core I5", 128, 1000000, "windoze 10", "1TB", "Graphics Card", 4)
        personal_computer(std::string manu, std::string seri, std::string cp, int mem, double spee, std::string op_sy, std::string disk, std::string graphics, int usb);
        ////////////////////////////////////ACCESSORS////////////////////////////////////
        std::string getManufacturer();
        std::string getModel();
        std::string getSerial();
        std::string getCpu();
        double getSpeed();
        int getMemory();
        std::string getDisksize();
        std::string getGraphicscard();
        int getUsbports();
        int getBootstate();
        std::string getOperating();
        ////////////////////////////////////MUTATORS////////////////////////////////////
        void bootup();
        void shutdown();
        void restart();

        void setManufacturer(std::string manu);
        void setModel(std::string mode);
        void setSerial(std::string seri);
        void setCpu(std::string cp);
        void setSpeed(double spee);
        void setMemory(int mem);
        void setDisksize(std::string disk);
        void setGraphicscard(std::string graphics);
        void setOperating(std::string op_sy);
        void setUsbports(int usb);
};
#endif // !HEADER_H 


Also using VS's default file is not the best idea. You should change the name. Usually I just use the class name as the file name and in the header guard, those first 2 lines.along with the last.

Andy
Topic archived. No new replies allowed.