1.

What will be the output of the following program? #include<iostream.h>class Student{public:Student (char pname[]=" "){strcpy(name,pname);average=semesterHours=0;}void addCourse(int hours,float grade){average=(semesterHours*average+grade); semesterHours+=hours;average=semesterHours;}int hours(){ return semesterHours; }float gpa(){ return average;}protected:char name[40];int semesterHours;float average;};class GradStudent:public Student{public:GradStudent(char pname[]=" "):Student(pname){ qual_grade=0;}int qualifier(){ return qual_grade; }protected:int qual_grade;};int main() { Student commerce("Saurabh 7/."); GradStudent gs;commerce.addCourse(4,2.5);gs.addCourse(4,3.0);return 0;}

Answer»

Above code will generate various compilation errors few of them are listed below–

i. strcpy(name,pname); gives error due to missing string.h file

ii. After adding the required header file code will execute but screen will appear blank due to missing output statements.



Discussion

No Comment Found

Related InterviewSolutions