| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:关于类的问题 这是出了什么问题啊?
取消只看楼主 加入收藏
qq384200403
Rank: 2
等 级:论坛游民
帖 子:35
专家分:39
注 册:2013-3-1
结帖率:87.5%
收藏
已结贴  问题点数:10 回复次数:0 
关于类的问题 这是出了什么问题啊?
#ifndef __CSTU_H__
#define __CSTU_H__
class CStu
{
 protected:
    char m_No[11];            
    char m_Name[11];         
    unsigned short  m_Age;  
    char m_Sex[3];            
    char *m_Rem;              
    unsigned int m_RemBytes;   
 public:
    void Show();                     
    unsigned int GetRemBytes();      
    bool SetNo(char *No);            
    char *GetNo();                        
    bool SetName(char *Name);         
    char *GetName();                          
    bool SetAge(unsigned short Age);  
    unsigned short GetAge();               
    bool SetRem(char *Rem);           
    char *GetRem();                          
    bool SetSex(char *Sex);           
    char *GetSex();
    CStu(const CStu &s);

};   
#endif
   #include"StdAfx.h"
#include <iostream>
#include <string>
#include "CStu.h"
using namespace std;
void CStu::Show()      
{
   cout<<"学号:"<<m_No<<endl;
   cout<<"姓名:"<<m_Name<<endl;
   cout<<"性别:"<<m_Sex<<endl;
   cout<<"年龄:"<<m_Age<<endl;
   cout<<"简历:"<<m_Rem<<endl;
}
unsigned int CStu::GetRemBytes()
{
    return m_RemBytes;
}
bool CStu::SetNo(char *No)
{
  if(strlen(No)!=10 )  
         return false;
  else
         strcpy(m_No,No);
  return true;  
}

char * CStu::GetNo()
{
    return m_No;
}
bool CStu::SetName(char *Name)
{
  if(strlen(Name)>=10 )
      return false;
  else
      strcpy(m_Name,Name);
  return true;  
}

char * CStu::GetName()
{
  return m_Name;
}
bool CStu::SetAge(unsigned short Age)
{
    if(Age>=60)  
        return false;
    else
        m_Age=Age;
    return true;
}

unsigned short CStu::GetAge()
{
    return m_Age;
}
bool CStu::SetRem(char *Rem)
{
    int Len=strlen(Rem);
    char *p=new char[Len+1];
             if(p==NULL)        
         return false;
            if(m_Rem!=NULL)
          delete []m_Rem;  
    m_RemBytes=Len;
    m_Rem=p;   
    strcpy(m_Rem,Rem);  
    return true;
}
char * CStu::GetRem()
{
    return m_Rem;
}
bool CStu::SetSex(char *Sex)
{
    if(strcmp("男",Sex)==0 || strcmp("女",Sex)==0)
      {
        strcpy(m_Sex,Sex);
        return true;
      }
    else                    
           return false;   
}

char *CStu::GetSex()
{
    return m_Sex;
};
CStu::CStu(const CStu &s)
{
  strcpy(m_No,s.m_No);         
  strcpy(m_Name,s.m_Name);
  strcpy(m_Sex,s.m_Sex);      
  m_Age=s.m_Age;                 
  if(s.m_Rem!=NULL)
   {
    m_RemBytes=s.m_RemBytes;
    m_Rem=new char[m_RemBytes+1];  
    strcpy(m_Rem,s.m_Rem);
   }
  else
   {
      m_Rem=NULL;
      m_RemBytes=0;
   }
  cout<<调用了复制函数<<end1;
}
 
 
#include"StdAfx.h"
#include <iostream>
#include <string>
#include "CStu.h"
using namespace std;
void main ()
{
    CStu s1("3110413030");
    s1.Show();
}   
   运行时提示 fatal error C1083: Cannot open precompiled header file: 'Debug/MY.pch': No such file or directory
  并且总是提示STDAFX.H 出错啊
图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: void public 
2013-03-21 12:53
快速回复:关于类的问题 这是出了什么问题啊?
数据加载中...
 
   



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

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