#include<iostream.h>
#include<string.h>
#include<conio.h>
class student{
public:
char name[20],sex;
student(){}
student(char *n,char s){
strcpy(name,n);
sex=s; }
virtualvoid print(){
cout<<"Name is"<<name;
cout<<"The gender is "<<sex;
}
};
class kid:public student{
private:
int age;
public:
kid(){}
kid(char *n,char s,int a):student(n,s){
age=a;
}
void print(){
cout<<"\nName is: "<<name;
cout<<"\nThe gender is: "<<sex;
cout<<"\nThe age is: "<<age;
}
void regist (int f){
if (f>5) cout<<"\nThis kid is in the first grade";
elseif(f==5) cout<<"\nThis kid is in the third level";
elseif (f>4) cout<<"\nThis kid is in the second level";
elseif(f>3) cout<<"\nThis kid is in the first level";
else cout<<"sorry to young";
}
};
void main(){
kid K;
int f;
cout<<"Enter the kids name: ";
cin>>K.name;
cout<<"\nEnter his\her gender: ";
cin>>K.sex;
cout<<"\nEnter the kids age: ";
cin>>f;
kid *h;
h=&K;
h->print();
h->regist(f);
getch();
}
//#include <iostream.h> // named "iostream" in modern C++
//#include <string.h> // named "cstring" in modern C++
#include <iostream>
#include <cstring>
#include <conio.h>
usingnamespace std;
class student
{
public:
char name[20], sex;
student() {}
student(char *n, char s)
{
strcpy(name, n);
sex=s;
}
virtual ~student() {} // needed if inherited
virtualvoid print()
{
cout<<"Name is"<<name;
cout<<"The gender is "<<sex;
}
};
class kid: public student
{
private:
int age;
public:
kid() {}
kid(char *n, char s, int a): student(n,s)
{
age=a;
}
void print()
{
cout<<"\nName is: "<<name;
cout<<"\nThe gender is: "<<sex;
cout<<"\nThe age is: "<<age;
}
void regist()
{
if (age>5) cout<<"\nThis kid is in the first grade";
elseif(age==5) cout<<"\nThis kid is in the third level";
elseif (age>4) cout<<"\nThis kid is in the second level";
elseif(age>3) cout<<"\nThis kid is in the first level";
else cout<<"sorry to young";
}
};
//void main() // must be int main() even if you don't return anything
int main()
{
kid K;
int f;
cout<<"Enter the kids name: ";
cin>>K.name;
cout<<"\nEnter his/her gender: ";
cin>>K.sex;
cout<<"\nEnter the kids age: ";
cin>>f;
//kid r(K.name,K.sex,f);
kid *r;
r = new kid(K.name, K.sex, f);
r->print();
r->regist();
delete r; // for every new, there must be a delete
getch();
}