|
-
December 23rd, 2010, 06:16 PM
#1
Class member initialization help
Hi all,
I was trying to build a class that includes the info about a specific course taken.
I tried to initialize all the class members using constructor... But I got some errors like:
1>d:\my documents\visual studio 2010\projects\classinfo\classinfo\main.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\my documents\visual studio 2010\projects\classinfo\classinfo\main.cpp(20): warning C4183: 'ini': missing return type; assumed to be a member function returning 'int'
1>d:\my documents\visual studio 2010\projects\classinfo\classinfo\main.cpp(16): error C2059: syntax error : '{'
1>d:\my documents\visual studio 2010\projects\classinfo\classinfo\main.cpp(16): error C2143: syntax error : missing ';' before '{'
1>d:\my documents\visual studio 2010\projects\classinfo\classinfo\main.cpp(16): error C2143: syntax error : missing ';' before '}'
Could anyone help me on that? Thanks a lot in advance...
Here is my code:
Code:
#include <iostream>
#include <string>
using namespace std;
class classinfo{
private:
string classname;
char instructor[15];
int credits;
string comments;
char grades;
public:
ini(){
classname="No Name";
instructor[15]={'N','O',' ','I','N','S','T','R','U','C','T','O','R','\0'};
credits=0;
comments="No Comments";
grades='U';
}
void getclass(string cstring){
classname=cstring;
}
void getinstructor(char* istring){
for(char *ibegin=instructor,*iend=instructor+15;ibegin!=iend;++ibegin){
*ibegin=*istring;
++istring;
}
}
void getcredits(int credit){
credits=credit;
}
void getcomments(string comment){
comments=comment;
}
void getgrades(char grade){
grades=grade;
}
void printclass(){
cout<<"Class Name: "<<classname<<endl;
cout<<"Class Instructor: ";
for(char *ibegin=instructor,*iend=instructor+15;ibegin!=iend;++ibegin)
cout<<*ibegin;
cout<<endl;
cout<<"Class credits: "<<credits<<endl;
cout<<"Class Comments: "<<comments<<endl;
cout<<"Class grade: "<<grades<<endl;
}
};
int main()
{
string temp;
char temp1[15]="Hal Carter";
char* p=temp1;
int cre;
char g;
classinfo class1,class2;
cout<<"The class info default is"<<endl;
class1.printclass();
cout<<"Please input the class name of your first class"<<endl;
cin>>temp;
class1.getclass(p);
cout<<"Please input the credits of your first class"<<endl;
cin>>cre;
class1.getcredits(cre);
cout<<"Please input the comments of your first class"<<endl;
cin>>temp;
class1.getcomments(temp);
cout<<"Please input the grade of your first class"<<endl;
cin>>g;
class1.getgrades(g);
cout<<"The class info:"<<endl;
class1.printclass();
cin.get();
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|