would someone take a look

the age wont appear , i think i know why but i dont know how to fix it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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; }
virtual void 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";
else if(f==5) cout<<"\nThis kid is in the third level";
else if (f>4) cout<<"\nThis kid is in the second level";
else if(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();
}
Why did you delete your original thread?
The code below is for your original post.

By the way, please tell me you are not using Borland C.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//#include <iostream.h> // named "iostream" in modern C++
//#include <string.h> // named "cstring" in modern C++
#include <iostream>
#include <cstring>
#include <conio.h>

using namespace std;

class student
{
public:
    char name[20], sex;

    student() {}

    student(char *n, char s)
    {
        strcpy(name, n);
        sex=s;
    }

    virtual ~student() {} // needed if inherited

    virtual void 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";
        else if(age==5) cout<<"\nThis kid is in the third level";
        else if (age>4) cout<<"\nThis kid is in the second level";
        else if(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();
}
Topic archived. No new replies allowed.