-
Please, help me! :S
Please, would you help me? I don`t know why this program doesn`t run.
Code:
#include <iostream>
#include <string>;
using namespace std;
class Item
{
public:
Item ()
int getPower() const;
int getWeight() const;
int getName() const;
void setPower();
void setWeight();
void setName();
void read();
void print() const;
private:
int power;
int weight;
char name[256];
};
void Item::read()
{
cout << "Power: ";
cin >> power;
cout << "Weight: ";
cin >> weight;
cout << "Name: ";
for (int i=0; i < 256; i++)
cin >> name[i];
}
void Item::print()
{
cout << "Power: " << power << endl;
cout << "Weight: " << weight << endl;
cout << "Name: " << name << endl;
void main ()
{
Item Item1;
Item1.setPower(63);
Item1.setWeight(86);
Item1.setName(23);
cout << Item1.getPower() << endl;
cout << Item1.getWeight() << endl;
cout << Item1.getName() << endl;
system("PAUSE");
}
-
Use int main() and in the end return 0.
-
Does it compile? Are you getting errors? If so what are they? Copy and paste them here. I don't see where you've created some of the functions your class is supposed to provide.
-
Errors are:
error C2144: syntax error : 'int' should be preceded by ';' c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 8
error C2511: 'void Item:: print(void)' : overloaded member function not found in 'Item' c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 40
fatal error C1004: unexpected end-of-file found c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 62
-
Missing a ;
And again...you've not provided an implementation for some of the methods you're trying to use.
-
Use ending brackets for this function.
Also, setPower() is not taking any parameters in the prototype but while calling you are passing a parameter....
Above all, you didn't define many of functions, atleast not here so that we could see.
And use int main() and in the end return 0, before ending braces of main()...
-
:)
Thank you of all!!! :):):)