Getting Garbage value in inheritance program

i m getting garbage value in an inheritance programme
the structure is like below
A B
\ /
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
#include<iostream.h>
#include<conio.h>
class person
{
	public:
	int name;
	void getdata()
	{
		cout<<"Enter tne name:::";
		cin>>name;
	}
	void putdata()
	{
		cout<<name;
	}
};
class student
{
	public:
	int enroll;
	void getdata1()
	{
		cout<<"Enter the enroll::";
		cin>>enroll;
	}
	void putdata1()
	{
		cout<<enroll;
	}
};
class exam:public person,public student
{
	public:
	int a,b,c,d,e,totmarks;
	float per;
	void getdata2()
	{
		cout<<"Enter marks::";
		cin>>a>>b>>c>>d>>e;
	}
	void putdata2()
	{
		totmarks=a+b+c+d+e;
		per=totmarks/5;
		cout<<totmarks<<"\t"<<per;
	}
};
void main()
{
	clrscr();
	exam e;
	e.getdata();
	e.putdata();
	e.getdata1();
	e.putdata1();
	e.getdata2();
	e.putdata2();
	getch();
}
Last edited on
int name;
how many people do we know who have numbers for names, use std::string name and getline(std::cin, name) after #include <string> header file at top of the program
you also have a lot of weird stuff in your program like void main(), some c-style header files (.h extensions) - if you're self-taught I suggest you get a good book like C++ Primer Plus (5th ed) - Stephen Prata and if you're learing at school .... well ....
Sorry buddy i just forget that name has type char not int.
thnx a lot for your help

And a question too,i m doing this program of pattern


a b
\ /
c
/ \
d e
i have done half of that ,now what should i do?
d:c e:c like that??
... name has type char ...

try entering your name into the following program:
1
2
3
4
5
6
7
#include<iostream>
int main()
{
	char name{};
	std::cin >> name;
	std::cout << name << "\n";
}
I have cleared that error when u told me about the data type but now i m asking about the other half pattern

c
/ \
d e
this
I have cleared that error when u told me ...

no, you made the char type for name error after I told you not to use int for names, review your posts
my point is not to belittle you but it appears that you have some lacunae in understanding basic C++ (admittedly we all do) like what types might be suitable for which variables etc
Topic archived. No new replies allowed.