Im having problems making a simple class. I made classes before but with the class I am working on now I cant seem to figure out the problem. When I compile it it gives me an error saying "23 C:\Dev-Cpp\project.cpp prototype for `int book::center(int, int)' does not match any in class `book' "
#include <cstdlib>
#include <iostream>
using namespace std;
class book {
int length, width, heigth, date;
public:
book (int, int, int, int);
int surfaceArea ();
int volume ();
int year ();
int center ();
};
book::book(int a, int b, int c, int d){
width=a;
length=b;
heigth=c;
date=d;
}
int book::center(int a, int b){
length=b/2;
width=a/2;
return length,width;
}
int book::volume(int a, int b, int c){
length=b;
width=a;
heigth=c;
return length*width*heigth;
}
int book::year(int d){
year=d;
return 2009-date;
}
int main(int argc, char *argv[])
{
cout <<"This book is "<<book.year(1980)<<" years old."<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Oh alright I see now. But I thought if you put center() its the same as center(int, int). Now I just have one more problem which is in the cout out part. its says 48 C:\Dev-Cpp\project.cpp expected primary-expression before '.' token
#include <cstdlib>
#include <iostream>
using namespace std;
class book {
int length, width, heigth, date;
public:
book (int, int, int, int);
int surfaceArea ();
int volume (int, int, int);
int year (int);
int center (int, int);
};
book::book(int a, int b, int c, int d){
width=a;
length=b;
heigth=c;
date=d;
}
int book::center(int a, int b){
length=b/2;
width=a/2;
return length,width;
}
int book::volume(int a, int b, int c){
length=b;
width=a;
heigth=c;
return length*width*heigth;
}
int book::year(int d){
date=d;
return 2009-date;
}
int main(int argc, char *argv[])
{
cout <<"This book is "<<book.year(1980)<<" years old."<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
OK so now I wrote it like this and it works finally. I need to use a destructor in class but our teacher never really explained it. So I tried to insert ~book() under book (int,int,int,int) as my destructor but it says [Linker error] undefined reference to `book::~book()' .
#include <cstdlib>
#include <iostream>
using namespace std;
class book {
int length, width, heigth, date;
public:
book ();
book (int, int, int, int);
int surfaceArea ();
int volume (int, int, int);
int year (int);
int center (int, int);
};
book::book(int a, int b, int c, int d){
width=a;
length=b;
heigth=c;
date=d;
}
int book::center(int a, int b){
length=b/2;
width=a/2;
return length,width;
}
int book::volume(int a, int b, int c){
length=b;
width=a;
heigth=c;
return length*width*heigth;
}
int book::year(int d){
date=d;
return 2009-date;
}
int main(int argc, char *argv[])
{
book car (5,5,5,1980);
cout <<"This book is "<<car.year(1980) <<" years old"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
lol well this is my first time ever taking a computer programming class. The teacher I have now doesnt teach very well. All he does is put codes on the board and expect us to know what it means.