2011年6月25日星期六

  第一篇日志:写个题目的乱实现吧

来csdn很久了呢,还没写过博客呢。本来不打算写的。但是某天上csdn的时候发现有人加我为好友,发现在程序员社区开始交友了哦,所以决定在在csdn写博客了。

本人很水的。菜鸟中的菜鸟呢。第一篇我不知道写什么,所以来写个书上题目的实现吧。没按书上的来,按着自己的意愿来的。

最近开始看boss jue的小说。我很喜欢,在此感谢boss jue 。开始不喜欢计算机类专业的,但是又读了,开始很郁闷。我的大学一半都没到点东西。现在认识到了,好像还不晚呢。

我相信如果我向boss jue一样努力。我定会成功的。在此推荐看这篇文章的程序员看一下《疯狂的程序员》很好。我相信接触这本书的人都会喜欢上这本书的。(在csdn上有连载,我还去看雪论坛找了那篇文章,现在想来还有点兴奋呢。

说了这么多还没开始题目上说的呢。

先来说下题目吧:

设计一个用于人事管理的“人员”类。由于考虑到通用性,这里抽象出所有的类型人员都具有的属性:编号,性别,出生日期,身份证等。其中“出生日期”声明的为一个“日期”的内嵌对象。用成员函数实现对人员信息的录入和提示。要求包括构造函数和析构函数,复制构造函数等。

今天看了点书(今年上的c++)决定按着自己的意愿来写。功能大概吧。(第一次就这样似乎不大好)

#include"stdafx.h"#include 
  using namespace std;class Date{private:    int year,mounth,day;public:    Date():year(0),mounth(0),day(0){}    Date(int y, int m, int d):year(y),mounth(m),day(d){}    void set(int y=0, int m=0 , int d=0)    {        year=y;        mounth=m;        day=d;    }    int  getyear()    {        return year;    }    int getmounth()    {        return mounth;    }    int  getday()    {        return day;    }    void show()    {        cout<<"year:"<
 
  <<
  "   mounth:"<
  
   <<
   "   day:"<
   
    class People:
    public Date{
    private:    
    int id,identity;    
    bool sex;
    public:    People():id(0),identity(0),sex(0)    {        Date::set(0,0,0);    }    People(
    int id, 
    int iden, 
    int s, 
    int y, 
    int m, 
    int d):id(id),identity(iden),sex(s)    {        Date::set(y,m,d);    }    
    void set(
    int id, 
    int iden ,
    int s, 
    int y, 
    int m, 
    int d)    {        
    this->id=id;        
    this->identity=iden;        
    this->sex=s;        Date::set(y,m,d);    }    
    void show()    {        cout<<
    "id:"<
    
     <<
     "    identity:"<
     
      <<
      "   sex:";        
      if (sex)        cout<<
      "male  ";        
      else            cout<<
      "female   ";        Date::show();        cout<
      
       int main(){    cout<<
       "please input the id,identity,sex,year,month,day";    People i;    People k(912,678,1,1990,9,8);    
       int id,identity,year,mounth,day;    
       bool sex;    cin>>id>>identity>>sex>>year>>mounth>>day;    People fa(id,identity,sex,year,mounth,day);    k.show();    fa.show();    cout<
       
      
     
    
   
  
 

这是我的源代码,写不是什么技术。但是呢是我第一次在csdn上写博客呢。

上面的程序用的继承的方式写的。没有复制构造函数。

我csdn开始很久了,但是这是csdn博客的开始。

没有评论:

发表评论