C++ 作业不会写,求大神帮忙。。。
声明一个computer类,该类有操作系统op,内存mem,硬盘hard三个属性,其中op为枚举类型(dos,windows,xp,win7,vista),mem和hard均为整形表示其容量。并设计几个函数分别获取属性质和设置属性值,并编程调试该类。并设计相应的构造函数和析构函数。两道程序。求大神帮忙。谢谢。
程序代码:computer.h
#ifndef COMPUTER_H
#define COMPUTER_H
enum OS_TYPE
{
OS_TYPE_DOS,
OS_TYPE_WINDOWS,
OS_TYPE_XP,
OS_TYPE_WIN7,
OS_TYPE_VISTA
};
//
static const char* STR_OS_TYPE[5] =
{
"dos",
"windows",
"xp",
"win7",
"vista"
};
//
class CComputer
{
public:
CComputer(OS_TYPE nType, const unsigned int& nMrySize, const unsigned int& nHrdSize);
~CComputer();
//
void set_os_mry(const unsigned int& nMrySize);
const unsigned int& get_os_mry(void) const;
//
void set_hard_cpty(const unsigned int& nHrdSize);
const unsigned int& get_hard_cpty(void) const;
//
void set_os_type(OS_TYPE nType);
const OS_TYPE get_os_type(void) const;
private:
OS_TYPE m_os_type; //default:windows
unsigned int m_nMrySize; //MB
unsigned int m_nHrdSize; //G
};
#endif
computer.cpp
#include "computer.h"
//default constructor
CComputer::CComputer(OS_TYPE nType, const unsigned int& nMrySize, const unsigned int& nHrdSize):
m_os_type(nType), m_nMrySize(nMrySize), m_nHrdSize(nHrdSize)
{
}
//default destructor
CComputer::~CComputer()
{
}
void CComputer::set_os_mry(const unsigned int& nMrySize)
{
m_nMrySize = nMrySize;
}
const unsigned int& CComputer::get_os_mry(void) const
{
return m_nMrySize;
}
void CComputer::set_hard_cpty(const unsigned int& nHrdSize)
{
m_nHrdSize = nHrdSize;
}
const unsigned int& CComputer::get_hard_cpty(void) const
{
return m_nHrdSize;
}
void CComputer::set_os_type(OS_TYPE nType)
{
m_os_type = nType;
}
const OS_TYPE CComputer::get_os_type(void) const
{
return m_os_type;
}
main.cpp
#include <iostream>
#include "computer.h"
int main()
{
CComputer OBJ(OS_TYPE_WINDOWS, 4096, 500);
std::cout<<"Before Operator system : "<<STR_OS_TYPE[OBJ.get_os_type()]<<std::endl;
std::cout<<"Before Memory capacity : "<<OBJ.get_os_mry()<<"(MB)"<<std::endl;
std::cout<<"Before HardDisk capacity : "<<OBJ.get_hard_cpty()<<"(G)"<<std::endl;
//set operator
std::cout<<std::endl;
OBJ.set_os_type(OS_TYPE_WIN7);
OBJ.set_os_mry(8092);
OBJ.set_hard_cpty(750);
std::cout<<std::endl;
//@set end
std::cout<<"Last Operator system : "<<STR_OS_TYPE[OBJ.get_os_type()]<<std::endl;
std::cout<<"Last Memory capacity : "<<OBJ.get_os_mry()<<"(MB)"<<std::endl;
std::cout<<"Last HardDisk capacity : "<<OBJ.get_hard_cpty()<<"(G)"<<std::endl;
return 0;
}








