We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This problem is driving me crazy! My code works for the first test case but fails on about half of them. I downloaded the textfiles for the input and output of one of the cases it fails on. Then I used the file as an input and piped the output to another file. I used a diff tool to see if there was any difference between the expected output and the generated output and there was none. If anyone can let me know what I am doing wrong I would greatly appreciate it.
staticintstudent_id,professor_id;classPerson{public:intage;stringname;// = 0 indicates pure virtual function, must be overriddenvirtualvoidgetdata()=0;// virtual function with definition, does not have to be overriddenvirtualvoidputdata()=0;};classProfessor:publicPerson{public:intpublications;intid;Professor(){++professor_id;}voidgetdata(){cin>>name>>age>>publications;id=professor_id;}voidputdata(){cout<<name<<" "<<age<<" "<<publications<<" "<<id<<endl;}};classStudent:publicPerson{public:intmarks[6];intmarks_sum;intid;Student(){++student_id;}voidgetdata(){cin>>name>>age;id=student_id;for(inti=0;i<6;i++){cin>>marks[i];marks_sum+=marks[i];}}voidputdata(){cout<<name<<" "<<age<<" "<<marks_sum<<" "<<id<<endl;}};
Virtual Functions
You are viewing a single comment's thread. Return to all comments →
This problem is driving me crazy! My code works for the first test case but fails on about half of them. I downloaded the textfiles for the input and output of one of the cases it fails on. Then I used the file as an input and piped the output to another file. I used a diff tool to see if there was any difference between the expected output and the generated output and there was none. If anyone can let me know what I am doing wrong I would greatly appreciate it.