#include <iostream>
#include <stdio.h>
using namespace std;
class Student
{
char *studname;
int studnum;
char gender;
public:
void setstudname(char*);
void setstudnum(int);
void setgender(char);
char getstudname();
int getstudnum();
char getgender();
};
void Student::setstudname(char *sd)
{
int i;
for(i=0; i<strlen(sd); i++)
{
if(!isalpha(sd[i]))
{
break;
}
}
if(i=strlen(sd))
{
studname=sd;
}
else
{
studname = "toot";
};
char *Student::getstudname()
{
return studname;
}
void Student::setstudnum(int sn)
{
if(sn >= 1 && sn <= 9)
{
studentnumber=sn;
}
}
int Student::getstudnum()
{
return studentnumber;
}
void Student::setgender(char sg)
{
if(toupper(sg) == 'M' || toupper(sg) == 'F')
{
gender = sg;
}
else
{
gender = 'B';
}
}
char Person::getGender()
{
return gender;
}
whats wrong with this program?
can you help me guys.. .
Are you getting an error?
Please use code tags, it makes it much easier to read and improves your chances of getting help.
First error I found when compiling your code is strlen is not defined, add
#include <cstring>
to your includes.
Add a closing brace before
1 2 3 4
|
char *Student::getstudname()
{
return studname;
}
|
The function
1 2 3 4
|
char Person::getGender()
{
return gender;
}
|
should be in class Student and the definition should have a capital G.
To fix all the errors check the definitions and declarations match and all opening braces have matching closing braces, the easiest way is to indect.
Last edited on