0

help.why can't my coding loop properly.,..i notice it can't show the loop of ptrpers[j] ?
what did i do wrong.?
it didn't show back the input i put on earlier.

#include<iostream>
using namespace std;

class person
{
protected:
	char name[40];
public:
	void setname()
	{
		cout<<"Enter Name:";
		cin>>name;
	}
	
	void putname()
	{cout <<"Name:"<<name<<endl;}

	virtual void getdata()=0;//pure virtual or abstrak
	virtual bool outstanding()=0;//pure virtual or abstrak
};

class prof:public person
{
	int numpub;
public:
	void getdata()
	{
		person::setname();
		cout<<"Enter number of prof's publication:";
		cin>>numpub;
	}
	bool outstanding()
	{return(numpub>60)? true:false;}
};
class stud:public person
{
	int mark;
public:
	void getdata()
	{
		person::setname();
		cout<<"Enter student mark:";
		cin>>mark;
	}
	bool outstanding()
	{return(mark>60)? true:false;}
};
int main()
{
	person*ptrpers[100];
	int n=0;//i=0;
	char choice;

	do{
		cout<<"enter student or prof,(s/p):";
		cin>>choice;
		if (choice == 's')
		ptrpers[n] = new stud;
	
		else
		ptrpers[n] = new prof;
		
		ptrpers[n]-> getdata();

	cout<<"enter another prson(y/n)?";
	cin>>choice;

	}while(choice=='y');

	for(int j=0;j<n;j++)
	{
		ptrpers[j] -> putname();
		if(ptrpers[j] -> outstanding() )
		{
			cout<<"person outstanding\n";
		}
	}
	return 0;
}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by MyRedz
0

Because you never increment "n" anywhere. In your do while, you need to stick an n++ some place.

0

thanks i didn't realize that mistake.now it works like a charm!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.