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;
}

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.