/* j_3_p_7
Create a class A that has height as private data member
& member functions to get & display it. Create a class B
that has width as data member & member functions to get &
display it. B class will inherits the A class. Create a
class C that inherits the B class. Create object of C class
and then access functions of A & B class. (Multilevel)
*/
#include <iostream.h>
#include <conio.h>
class A
{
private:
int height;
public:
void get()
{
cout << "Enter Height : ";
cin >> height;
}
void display()
{
cout << endl << "Height is : " << height;
}
};
class B : public A
{
public:
int width;
public:
void getB()
{
cout << "Enter width : ";
cin >> width;
}
void displayB()
{
cout << endl << "Height is : " << width;
}
};
class C : public B
{};
void main()
{
clrscr();
C obj;
obj.get();
obj.display();
obj.getB();
obj.displayB();
getch();
}
7.Write a program to read a list containing item name, item code and cost interactively and produce a three-column output as shown below. NAME CODE COST Turbo C++ 1001 250.95 C Primer 905 95.70 ------------- ------- ---------- ------------- ------- ---------- Note that the name and code are left-justified and the cost is right-justified with a precision of two digits. Trailing zeros are shown.
/*J_4_P_8 Write a program to read a list containing item name, item code and cost interactively and produce a three-column output as shown below. NAME CODE COST ======================= Turbo C++ 1001 250.95 C Primer 905 95.70 ------------- ------- ----------------- ------------- ------- ----------------- Note that the name and code are left-justified and the cost is right-justified with a precision of two digits. Trailing zeros are shown. */ #include <iostream.h> #include <iomanip.h> #include <string.h> #include <conio.h> class item { char name[40]; int code; float cost; public: void get_data(char *n, int c, float co)...
Comments
Post a Comment