EDIT -- line numbers in this post are referring to the line numbers in your second post in the thread, not your most recent one.
EDIT again: if you want to use std::string, you need to #include <string>. Also because you're
using namespace std;
you can just use
string
instead of typing out
std::string
.
1 2 3 4 5 6
|
// different variable types hold different types of variables
// example
int anInteger; // for holding numbers (integers only, no floating point), ie: 1,2,-5, but not 1.5
float aFloat; // for holding floating point numbers. ie: 1.5, 1.7, etc
char aCharacter; // for holding an INDIVIDUAL character. ie: 'c', 'a', 'B'
std::string aString; // for holding full strings. ie: "foo", "bar"
| |
If you want your Computer class to retain information about the computer, think about what kind of variables you want to use.
Also if you want to use a string literal (ie, you want it to actually SAY "pc" or you want to assign the string "pc" to something) you need to encase the string in quotes.
1 2
|
cout << blah; // prints the contents of a variable named blah
cout << "blah"; // prints the actual word blah
| |
Double quotes
"
go around strings, and single quotes
'
go around chars.
I really dont understand how to do this line? fraction make (pc) more explanation would help
|
This is a
constructor (aka, 'ctor'). A constructor is just like any other function, only it is called when an object is created. In your code, your ctor is on line 5. It takes two parameters,
pc and
amd. If you want to call that constructor, you need to supply values for each of those.
On line 12 you're making two Computer objects, and giving 1 parameter to each of their ctors (not 2!). You're basically creating two computers, one with make=pc, and another with make=amd (but the model for each is never specified)
To call the ctor properly, you need to give it two parameters:
|
computer mycomp( /*put desired make here*/ , /*put desired model here*/ );
| |
That will create a 'mycomp' computer object and will call the computer ctor, which will set up your make and model.