A class named Processor has
•Two attributes i.e. processName and price
•A parameterized constructor to initialize attributes with user-defined values
Class MainMemory consists of
•Two attributes i.e. size and price
•A parameterized constructor to initialize attributes with user-defined values
Class MotherBoard has
•a data member named compName of type string
•a no-argument constructor to initialize with default name intel
Design a class named Computer that includes
•A data member named proc of type Processor
•A data member named ram of type MainMemory
•A data member named mboard of type MotherBoard
•A parameterized constructor that accept two arguments of type Processor and MainMemory to initialize members of these types. Moreover, within this constructor, instantiate object of MotherBoard to initialize mboard data field.
Write a main() and create necessary objects of the classes and call the corresponding functions.
#include <iostream>
class Processor
{
public:
Processor(double cost, std::string name);
Processor();
~Processor();
double get_cost()
{
return cost;
}
std::string get_name()
{
return name;
}
void set_cost(double cost)
{
this->cost = cost;
}
void set_name(std::string name)
{
this->name = name;
}
private:
double cost;
std::string name;
};
Processor::Processor(double cost , std::string name)
{
this->name = name;
this->cost = cost;
}
Processor::Processor()
{
name = "";
cost = 0;
}
Processor::~Processor()
{
}
//mem
class MainMemory
{
public:
MainMemory();
MainMemory(int size , double cost);
~MainMemory();
void set_cost(double cost)
{
this->cost = cost;
}
double get_cost()
{
return cost;
}
void set_size(int cost)
{
this->size = size;
}
int get_size()
{
return size;
}
private:
int size;
double cost;
};
MainMemory::MainMemory(int size, double cost)
{
this->size = size;
this->cost = cost;
}
MainMemory::MainMemory()
{
size = 0;
cost = 0;
}
MainMemory::~MainMemory()
{
}
//moth
class MotherBoard
{
public:
MotherBoard();
MotherBoard(std::string compName);
~MotherBoard();
std::string get_comp_name()
{
return compName;
}
void set_comp_name(std::string compName)
{
this->compName = compName;
}
private:
std::string compName;
};
MotherBoard::MotherBoard(std::string compName)
{
this->compName = compName;
}
MotherBoard::MotherBoard()
{
this->compName = "intel";
}
MotherBoard::~MotherBoard()
{
}
//comp
class Computer
{
public:
Computer();
Computer(Processor proc , MainMemory ram , MotherBoard mboard);
~Computer();
Processor get_proc()
{
return this->proc;
}
MainMemory get_ram()
{
return this->ram;
}
MotherBoard get_mboard()
{
return this->mboard;
}
void set_proc(Processor proc)
{
this->proc = proc;
}
void set_ram(MainMemory ram)
{
this->ram = ram;
}
void set_mboard(MotherBoard mboard)
{
this->mboard = mboard;
}
private:
Processor proc;
MainMemory ram;
MotherBoard mboard;
};
Computer::Computer(Processor proc, MainMemory ram , MotherBoard mboard)
{
this->proc = proc;
this->ram = ram;
this->mboard = mboard;
}
Computer::Computer()
{
}
Computer::~Computer()
{
}
int main()
{
std::string name;
double cost;
std::cout << "Processor name : "; std::cin >> name;
std::cout << "Processor cost : "; std::cin >> cost;
Processor proc(cost,name);
int size;
std::cout << "Main memory size : "; std::cin >> size;
std::cout << "Main memory cost : "; std::cin >> cost;
MainMemory mem(size, cost);
std::cout << "Motherboard name : "; std::cin >> name;
MotherBoard mb(name);
Computer comp(proc, mem, mb);
std::cout << "\nYour computer : \n";
std::cout << "\tProcessor : Name : " << comp.get_proc().get_name() << " , Cost : " << comp.get_proc().get_cost() << '\n';
std::cout << "\tMain memory : Size : " << comp.get_ram().get_size() << " , Cost : " << comp.get_ram().get_cost() << '\n';
std::cout << "\tMotherboard : Name : " << comp.get_mboard().get_comp_name() << '\n';
system("pause");
return 0;
}
Comments
Leave a comment