Write a program to implement the following hierarchy using suitable member functions. Refer Figure No.2.

electronics2electrical.com 704 -  .jpg

1 Answer

Answer :

# include <iostream.h>

#include<conio.h>

class Student

{

int roll_no;

char name[10];

public:

void read_studentData()

{

cout<<”Enter student‟s roll no and name \n”;

cin>>roll_no>> name;

}

void display_studentData ()

{

cout<<”\n roll_no\t name\n”;

cout<<roll_no<<”\t”<<name<<”\n”;

}

};

class test: public Student

{

protected:

int marks1,marks2;

public:

void read_test()

{

cout<<”\n Enter test marks\n”;

cin>>marks1>>marks2;

}

void display_test()

{

cout<<”\n test Marks \n Marks1 \t Marks2 \n”;

cout<<marks1<<”\t”<<marks2;

}

};

class sports

{

int score;

public:

void read_sportsData()

{

cout<<”\n Enter sport score\n”;

cin>> score;

}

void display_sportsData()

{

cout<<”\n sport score:”<<score;

}

};

class result: public test, public sports

{

int total;

public:

void read_result()

{

read_ studentData () ;

read_test();

read_sportsData();

total=marks1+marks2;

}

void display_result()

{

display_ studentData () ;

display_test();

display_sportsData();

cout<<”\n Total=”<<total;

}

};

void main()

{

result r;

clrscr();

r.read_result();

r.display_result();

getch();

}


Related questions

Description : Write a program to implement single inheritance from the following Refer Figure No.1

Last Answer : #include #include class employee { protected: int emp_id; char name[10]; }; class emp_info:public employee { int basic_salary; public: void getdata() { coutemp_id; coutname; coutbasic_salary; } void putdata() { cout

Description : Write a program to implement multiple inheritance as shown in following Figure No.1: Accept and display data for one object of class result.  

Last Answer : Program: #include<iostream.h> #include<conio.h> class Subject1 { protected: float m1; }; class Subject2 { protected: float m2; }; class Result:public Subject1,public Subject2 { ... ; clrscr(); r.accept(); r.calculate(); r.display(); getch(); }

Description : Write a program to declare a class ‘book’ containing data members as ‘title’, ‘author-name’, ‘publication’, ‘price’. Accept and display the information for one object using pointer to that object.

Last Answer : #include<iostream.h> #include<conio.h> class book { char author_name[20]; char title[20]; char publication[20]; float price; public: void Accept(); void Display(); }; void ... title \t author_name \t publication \t price\n ; p-> Display(); getch(); }

Description : Write two properties of static member function

Last Answer : i) A static member function can have access to only other static data members and functions declared in the same class. ii) A static member function can be called using the class name with a scope resolution operator instead of object name as follows: class_name::function_name;

Description : What is multilevel inheritance? Draw the diagram to show multilevel inheritance. using classes with data member and member function. 

Last Answer : When a class is derived from another derived class then it is called as multilevel inheritance.

Description : Write a program in C++ to implement following inheritance. Assume suitable data.

Last Answer : #include<iostream.h> #include<conio.h> class employee { int empid; char empname[20]; public: void accept() { cout<<"\n enter empid, empname:"<<endl; cin>>empid>> ... m.acc1(); m.dis1(); w.acc2(); w.dis2(); getch(); }

Description : Write a C++ program to implement inheritance shown in following figure: Accept and display data of one teacher and one student using object of class ‘Info’

Last Answer : #include<iostream.h> #include<conio.h> class Teacher { protected: char Name[20]; int empid; }; class Student { protected: char sname[20]; int rollno; }; class Info:public ... I.acceptT(); I.displayT(); I.acceptS(); I.displayS(); getch(); }

Description : Write a program to implement the concept of virtual base class for following figure. Accept and display information of one employee with his name, code, basic pay, experience and gross salary with the object of employee class.

Last Answer : #include<iostream.h> #include<conio.h> class Master  {  char name[10],code[3];  public:  void acceptM() { cout<<"\nEnter name and code "; cin>>name>>code; ... .displayM(); e.displayA(); e.displayD(); e.displayE(); getch();  }

Description : Write a program in C++ to implement single inheritance from following figure:

Last Answer : #include<iostream.h> #include<conio.h> class product { protected: int prodid; char prodname[20]; }; class edible:public product { char flavour[20]; public: void accept() { cout<< ... for(i=0;i<5;i++) { e[i].display(); } getch(); }

Description : What is the need to implement memory as a hierarchy?

Last Answer : The aim of the memory hierarchy is to match the processors speed with the rate of information transfer at a lowest level and at a minimum possible cost

Description : Write a program that copies contents of one file into another file.

Last Answer : Assuming input file to be copied file1.txt contents are “Hello Friends…” and file where the contents need to copy is file2.txt already created  #include #include #include #include #include void main() { clrscr(); ifstream fs; ofstream ft; char ch, fname1[20], fname2[20]; cout

Description : Write a program to overload the ‘—’ unary operator to negate the values.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class Number { int x,y; public: Number (int a, int b) { a =x; b =y; } void display() { cout<< ... ; -N1; cout<<"\n After negation:"; N1. display (); getch (); }

Description : Write a program to count the number of lines in file.

Last Answer : #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { ifstream file; char ch; int n=0; clrscr(); file.open("abc.txt"); while(file) { file. ... \n Number of lines in a file are:"<<n; file.close(); getch(); }

Description : Write a program to sort an 1-d array in ascending order.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int arr[20]; int i, j, temp,n; clrscr(); cout<<"\n Enter the array size:"; cin>>n; cout<<"\n Enter ... 0;i<n;i++) {  cout<< \n <<arr[i]; } getch(); }

Description : Explain virtual base class with suitable example.

Last Answer : Consider a situation where all three kinds of inheritance, namely, multilevel, multiple, hierarchical inheritance, are involved. This illustrated in fig a. the child has two direct base classes, parent1 & ... Grandparent { }; class Child: public Parent1,public Parent2 { };

Description : Write the applications of object oriented programming.

Last Answer : Applications of object oriented programming are: 1) Real time systems 2) Simulation and modeling 3) Object-oriented databases 4) Hypertext, hypermedia and expertext 5) AI and expert systems ... and parallel programming 7) Decision support and office automation systems 8) CIM/CAM/CAD systems

Description : Write any four benefits of OOP. 

Last Answer : Benefits of OOP: 1. We can eliminate redundant code and extend the use of existing classes. 2. We can build programs from the standard working modules that communicate with one another, ... interface descriptions with external systems much simpler. 10. Software complexity can be easily managed.

Description : Write a C++ program to implement following inheritance. Accept and display data for one programmer and one manager. Make display function virtual.  

Last Answer : #include #include class Employee  { int empid,empcode; public: void emp() { coutempid; coutempcode; } void virtual display() { cout

Description : Write a program which implement the concept of overloaded constructor.

Last Answer : #include #include class integer { int m,n; public: integer() { m=0; n=0; } //default constructor 1 integer(int a, int b) { m=a; n=b; } //Parameterized constructor 2 integer(integer &i) { m=i.m; n=i.n; } //copy constructor 3 }; void display() { cout

Description : Write a program to implement single inheritance. Declare base class employee with Emp_No. and Emp_Name. Declare derived class fitness with height and weight. Accept and display data for one employee.

Last Answer : #include<iostream.h> #include<conio.h> class employee { protected: int emp_no; char emp_name[10]; public: void gete() { cout<< enter employee details ; cin>>emp_no; cin>> ... f.gete(); f.pute(); f.getft(); f.putft(); getch(); }

Description : Implement a program to declare a class city with data members city name and state. Accept and display data for 1 object using pointer to object.

Last Answer : #include<iostream.h> #include<conio.h> class city { char city_name[20],state[20]; public: void accept() { cout<<"\nEnter city data:"; cout<<"\nName:"; ... ); ptr=&c; ptr->accept(); ptr->display(); getch(); }

Description : The tillage implement, most suitable for rice cultivation is

Last Answer : Ans.Power tiller

Description : 0ff-set disc harrows are best suitable to work for a) primary implement b) breaking clods c) orchard cultivation d) surface finishing

Last Answer : c) orchard cultivation

Description : The electronic circuits which implement the various logic operations are called ________ (a) Logic gates (b) Boolean algebra (c) amplifier gain (d) logic functions

Last Answer : a) Logic gates

Description : Explain the friend function with proper example.

Last Answer : Friend function: The private members of a class cannot be accessed from outside the class but in some situations two classes may need access of each other s private data. So a common function can be declared which can be made friend ... ; } friend void swap(A,B); }; void swap(A a,B b) { cout

Description : What is parameterized constructor?

Last Answer : A constructor that accepts parameters is called as parameterized constructor. In some applications, it may be necessary to initialize the various data members of different objects with different values when they are ... an argument. Member function put ( ) displays the value of data member m .

Description : What are the rules for virtual function?

Last Answer : Rules for virtual function: 1. The virtual functions must be members of some class. 2. They cannot be static members. 3. They are accessed by using object pointers. 4. A virtual function can ... virtual function is defined in the base class, it need not be necessarily redefined in the derived class.

Description : What is inheritance? Give different types of inheritance.

Last Answer : Inheritance: The mechanism of deriving new class from an old/existing class is called inheritance. OR Inheritance is the process by which objects of one class acquired the properties of ... is a combination of single, multiple, multilevel and hierarchical inheritance. Diagram:

Description : State the rules for writing destructor function.

Last Answer : Rules for writing destructor function are: 1) A destructor is a special member function which should destroy the objects that have been created by constructor. 2) Name of destructor and name of the class should ... should not be classified in any types. 7) A class can have at most one destructor. 

Description : Describe ‘this’ pointer with an example.

Last Answer : this' pointer:  C++ uses a unique keyword called this to represent an object that invokes a member function. This unique pointer is automatically passed to a member function when it is invoked. ... pointer is used to represent object s when setdata ( ) and putdata ( ) functions are called. 

Description : Describe memory allocation for objects.

Last Answer : The memory space for object is allocated when they are declared and not when the class is specified. The member functions are created and placed in memory space only once when they are ... are essential because the member variables will hold different data values for different objects.

Description : Give syntax and use of fclose ( ) function.

Last Answer : Syntax:  int fclose(FILE* stream); Use: This function is used to close a file stream. The data that is buffered but not written is flushed to the OS and all unread buffered data is discarded.

Description : Explain use of scope resolution operator.

Last Answer : It is used to uncover a hidden variable. Scope resolution operator allows access to the global version of a variable. The scope resolution operator is used to refer variable of class anywhere in program. ... outside of class. Return_type class_name:: function_name( ) { Function body }

Description : What is a class? Give its example. 

Last Answer : Class is a user defined data type that combines data and functions together. It is a collection of objects of similar type. Example: class Student { int rollno; char name[10]; public: void getdata( ); void putdata( ); };

Description : State the difference between OOP and POP.

Last Answer : OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURE ORIENTED PROGRAMMING (POP) Focus is on data rather than procedure. Focus is on doing things (procedure). Programs are divided into multiple ... approach is used in C++ language. Procedure oriented approach is used in C language.

Description : How do you refer to a member in the base class?

Last Answer : To refer to a member in the base class use:return base.NameOfMethod(). 

Description : The new organization established to implement the Fifth Generation Project is called _____________ a) ICOT (Institute for New Generation Computer Technology) b) MITI (Ministry of International ... c) MCC (Microelectronics and Computer Technology Corporation) d) SCP (Strategic Computing Program)

Last Answer : a) ICOT (Institute for New Generation Computer Technology)

Description : Implement a program to demonstrate concept of pointers to function.

Last Answer : Pointer to function: include int sum(int x, int y) { return x+y; } int main() { int s; int(*fp)(int, int); fp = sum; s = fp(10,12); printf(“Sum = %d”,s); return 0; }

Description : Implement a program to demonstrate logical AND operator.

Last Answer : #include #include void main() { int i; int j; clrscr(); printf("Enter the values of i and j"); scanf("%d%d",&i,&j); if(i==5 && j==5) { printf("Both i and j are equal to 5"); } else { printf("Both the values are different and either or both are not equal to 5"); } getch(); }

Description : …………. Refer to the names of variables, functions, arrays, classes etc. created by the programmer. A) Keywords B) Identifiers C) Constraints D) Strings

Last Answer : B) Identifiers

Description : .............. predicate calculus allows quantified variables to refer to objects in the domain of discourse and not to predicates or functions. (A) Zero-order (B) First-order (C) Second-order (D) High-order

Last Answer : (B) First-order

Description : State True or False. i) A satic function can have access to only other static members (functions or variables) declared in the same class. ii) A static member function can be called using the class name (instead of its objects) A) True, True B) True, False C) False, True D) False, False

Last Answer : B) True, False

Description : Refer to figure 3-55(A). If the following resistors were replaced with the values indicated: R1 = 900Ω, R3 = 1kΩ, what is the total power in the circuit? What is ER2?

Last Answer : PT = 60 W, ER2 = 10 V.

Description : Refer to figure 2-3(B). Why is the sulfuric acid decreasing?

Last Answer : The sulfuric acid is chemically acting upon the anode and cathode which creates a current flow through the load

Description : Which one of the following is correct, when a class grants friend status to another class? (A) The member functions of the class generating friendship can access the members of the friend class. (B) ... the friendship. (C) Class friendship is reciprocal to each other (D) There is no such concept.

Last Answer : All member functions of the class granted friendship have unrestricted access to the members of the class granting the friendship. 

Description : Write a program to declare structure employee having data member name, age, street and city. Accept data for two employees and display it.

Last Answer : #include<stdio.h> #include<conio.h> struct employee { char name[10],street[10],city[10]; int age; }; void main() { int i; struct employee e[2]; clrscr(); for(i=0;i<2 ... =%s",e[i].street); printf("\n City=%s",e[i].city); } getch(); }

Description : Write a program to declare class having data member as hrs, mins, secs. Write constructor to assign values and destructor to destroy values. Accept & display data for one object.

Last Answer : #include<iostream.h> #include<conio.h> class time { private: int hrs, mins,sec; public: time(int h,int m,int s) { hrs=h; mins=m; sec=s; } ~time() { cout<< hours ... } }; void main() { time t(2,43,56); t.display(); getch(); }

Description : In a CNC program block, N05 GO1 G91 G33 X20 Z-40 K5……, K refer to a.Depth of cut b.Pitch c.Multiple Threading Cycle d.Feed

Last Answer : b.Pitch

Description : In CNC Program M98 is refer to…… a.CANCEL Subroutine b.Call Sub-Program c.Call Subroutine d.CANCEL Sub-Program

Last Answer : b.Call Sub-Program

Description : In CNC Program M03 is refer to…… a.Spindle ON in Clockwise rotation b.Spindle ON in Counter Clockwise rotation c.Spindle OFF in Clockwise rotation d.Spindle OFF in Counter Clockwise rotation

Last Answer : a.Spindle ON in Clockwise rotation