Завдання:
У програмі задіяний клас «Мій комп’ютер» із множинним успадкуванням.
#include <iostream.h>
#include <conio.h>
#include <string.h>
class computer_screen
{
public:
computer_screen(char *, long, int, int);
void show_screen(void);
private:
char type[32];
long colors;
int x_resolution;
int y_resolution;
};
computer_screen::computer_screen(char *type, long colors, int x_res, int y_res)
{
strcpy(computer_screen::type, type);
computer_screen::colors = colors;
computer_screen::x_resolution = x_res;
computer_screen::y_resolution = y_res;
}
void computer_screen::show_screen(void)
{
cout << "Tup monitora: " << type << endl;
cout << "Koljoru: " << colors << endl;
cout << "Rozrishennia: " << x_resolution << " na " << y_resolution << endl;
}
class mother_board
{
public:
mother_board(int, int, int);
void show_mother_board(void);
private:
int processor;
int speed;
int RAM;
};
mother_board::mother_board(int processor, int speed, int RAM)
{
mother_board::processor = processor;
mother_board::speed = speed;
mother_board::RAM = RAM;
}
void mother_board::show_mother_board(void)
{
cout << "Proc: " << processor << endl;
cout << "Chastota: " << speed << "MHz" << endl;
cout << "OZY: " << RAM << " MB" << endl;
}
class computer : public computer_screen, public mother_board
{
public:
computer(char *, int, float, char *, long, int, int, int, int, int);
void show_computer (void);
private:
char name [64];
int hard_disk;
float floppy;
};
computer::computer(char *name, int hard_disk, float floppy, char *screen, long colors, int x_res, int y_res, int processor, int speed, int RAM) : computer_screen(screen, colors, x_res, y_res), mother_board(processor, speed, RAM)
{
strcpy(computer::name, name);
computer::hard_disk = hard_disk;
computer::floppy = floppy;
}
void computer::show_computer(void)
{
cout << "Tup: " << name << endl;
cout << "HDD: " << hard_disk << "MB" << endl;
cout << "Floopyk: " << floppy << "MB" << endl;
show_mother_board();
show_screen();
}
void main(void)
{
clrscr();
computer my_pc("Athlon", 120000, 1.44, "SVGA", 4294967296, 1024, 720, 2500, 18300, 512);
my_pc.show_computer();
}