| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 571 人关注过本帖
标题:C++ 作业不会写,求大神帮忙。。。
只看楼主 加入收藏
我是C渣渣
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-10-31
结帖率:0
收藏
 问题点数:0 回复次数:2 
C++ 作业不会写,求大神帮忙。。。
声明一个computer类,该类有操作系统op,内存mem,硬盘hard三个属性,其中op为枚举类型(dos,windows,xp,win7,vista),mem和hard均为整形表示其容量。并设计几个函数分别获取属性质和设置属性值,并编程调试该类。并设计相应的构造函数和析构函数。两道程序。求大神帮忙。谢谢。
搜索更多相关主题的帖子: computer windows vista 操作系统 
2014-11-07 16:20
xufan
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:232
专家分:804
注 册:2008-10-20
收藏
得分:0 
程序代码:
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;
}

~~~~~~我的明天我知道~~~。
2014-11-07 17:15
我是C渣渣
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-10-31
收藏
得分:0 
哇。同学你好厉害喔,可是我运行不了这个程序,而且我还没有学那么深,其实我不会定义一个类封装后再引用啊。老师说以后教,我现在只想用简单易懂的方法学会。大神可以解释一下吗?谢谢~
2014-11-10 00:29
快速回复:C++ 作业不会写,求大神帮忙。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022545 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved