| | |
need help on my inheritance here
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 25
Reputation:
Solved Threads: 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.
what did i do wrong.?
it didn't show back the input i put on earlier.
C++ Syntax (Toggle Plain Text)
#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; }
![]() |
Similar Threads
- need idea for project using classes and inheritance (C++)
- Inheritance (C++)
- Need example of how to use INHERITANCE! (C++)
- C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays (C++)
- Inheritance & Derived Classes (C++)
Other Threads in the C++ Forum
- Previous Thread: Implementing Linked List iterator, gcc is acting wierd
- Next Thread: reading file into multidimensional array
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






