游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1744|回复: 2

大家好.我初学C++.遇到困难了,请大家帮帮我.谢谢!

[复制链接]

15

主题

49

帖子

55

积分

注册会员

Rank: 2

积分
55
发表于 2006-12-10 21:38:00 | 显示全部楼层 |阅读模式
大家好.我初学C++.请教一下这道题该怎么做.
有下列要求:
1。从键盘读入一个整数N
2。随后,读入N个学生的信息,每个学生信息包括学号,姓名,出生日期
3。再输入一个日期date
4。取出输入日期date之前出生的所有学生的信息,按照年龄从小到大,输出姓名和出生日期
5。程序设计中,尽量减少程序运行的内存需求.日期表示采用以下定义

class Date
{
        int year,month,day;
public:
        Date(int y,int m,int d){year=y;month=m;day=d;}
        void point()
        {
                cout<<year<<" "<<month<<" "<<day;
        }
        int before(Date d)
        {
                if(year<d.year) return 1;
                if(year==d.year)
                {
                        if(month<d.month) return 1;
                        if(month==d.month) return day<d.day;
                }
                return 0;
        }
};

8

主题

716

帖子

716

积分

高级会员

Rank: 4

积分
716
发表于 2006-12-11 10:45:00 | 显示全部楼层

Re:大家好.我初学C++.遇到困难了,请大家帮帮我.谢谢!

we can help you debug your own code, but we couldn't code for you.

21

主题

92

帖子

92

积分

注册会员

Rank: 2

积分
92
QQ
发表于 2006-12-11 11:18:00 | 显示全部楼层

Re:大家好.我初学C++.遇到困难了,请大家帮帮我.谢谢!

我想先
1.设一个学生的类
class student
{
protected:
int Num;
char Name[10];
int  Birthday;

public:
void SetNum(int num){Num=num;}
int   GetNum(){return Num;}
void SetName(char*  name){strcopy(Name,name);}
char* GetName(){return Name}
void SetBirthday(int birthday){Birthday=birthday;}
int  GetBirthday(){return Birthday;}
}

2.student StuInfo[n];
   Date date;

3.int temp[],j=0;
for(int i=0;i<n;i++)
{
if(date->before(StuInfo->GetBirthday()))
{
//把日期小于指定日期的学生信息存储在temp[]中
temp[j]=i;
j++;
}
}

4.排序输出
//恩~似乎不够效率
//呵呵~ 我也是新手,说的不对的地方不要笑我啊~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 02:01

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表