永发信息网

跪求一个300多行的C++程序 ?

答案:2  悬赏:20  手机版
解决时间 2021-04-21 03:11
只要是能够运行的 程序就好 300多行就行 额 我能给的最高分可以都给你
最佳答案

#include <iostream>
using namespace std;
class Date
{
private:
int year;
int month;
int day;
friend void inputDate(Date& d);
friend int goday(Date& d);
friend void frontDate(Date& d);
friend void backDate(Date& d);
friend int distanceDate(Date& d1,Date& d2);
public:
Date(int y=0,int m=0,int d=0):year(y),month(m),day(d)
{}
void print()
{
cout<<year<<"\t"<<month<<"\t"<<day<<"\t";
}


};
void inputDate(Date& d)
{
cout<<"Please input year:"<<"\t";
cin>>d.year;
cout<<"Please input month:"<<"\t";
cin>>d.month;
cout<<"Please input day:"<<"\t";
cin>>d.day;
}
int goday(Date& d)
{
if((d.year%4==0&&d.year%100!=0)||d.year%400==0)
{

if(d.month<=2)
return (d.month-1)*31+d.day;
else if(d.month>2&&d.month<=7)
{
if(d.month%2==1)
return 60+d.day+61*(d.month-3)/2;
else if(d.month%2==0)
return 60+d.day+61*(d.month-4)/2+31;
}
else if(d.month>7)
{
if(d.month%2==0)
return 213+d.day+61*(d.month-8)/2;
else if(d.month%2==1)
return 213+d.day+61*(d.month-9)/2+31;
}


}
else
{
if(d.month<=2)
return (d.month-1)*31+d.day;
else if(d.month>2&&d.month<=7)
{
if(d.month%2==1)
return 59+d.day+61*(d.month-3)/2;
else if(d.month%2==0)
return 59+d.day+61*(d.month-4)/2+31;
}
else if(d.month>7)
{
if(d.month%2==0)
return 212+d.day+61*(d.month-8)/2;
else if(d.month%2==1)
return 212+d.day+61*(d.month-9)/2+31;
}


}
}
void frontDate(Date& d)
{
if(d.month==1&&d.day==1)
{
--d.year;
d.month=12;
d.day=31;
}
else if(d.month==2&&d.day==1)
{
d.month=1;
d.day=31;
}
else if(d.month==3&&d.day==1)
{
if(d.year%4==0&&d.year%100!=0||d.year%400==0)
{
d.month=2;
d.day=29;
}
else
{
d.month=2;
d.day=28;
}


}
else if(d.month>3&&d.month<=7&&d.day==1)
{
if(d.month%2==0)
{
--d.month;
d.day=31;
}
else
{
--d.month;
d.day=30;
}
}
else if(d.month==8&&d.day==1)
{
--d.month;
d.day=31;
}


else if(d.month>8&&d.day==1)
{
if(d.month%2==0)
{
--d.month;
d.day=30;
}
else
{
--d.month;
d.day=31;
}
}
else if(d.day!=1)
{
--d.day;
}

cout<<d.year<<"\t"<<d.month<<"\t"<<d.day<<"\t";
}
void backDate(Date& d)
{
if(d.month==12)
{
if(d.day==31)
{
++d.year;
d.month=1;
d.day=1;
}
else
{
++d.day;
}
}
else if(d.month==1)
{
if(d.day==31)
{
++d.year;
d.month=2;
d.day=1;
}
else
++d.day;
}


else if(d.month=2)
{
if(d.year%4==0&&d.year%100!=0||d.year%400==0)
{
if(d.day==29)
{
d.day=1;
d.month=3;
}
else
{
++d.day;
}
}
else
{
if(d.day==28)
{
d.day=1;
d.month=3;
}
else
{
--d.day;
}
}
}
else if(d.month!=2&&d.month!=12)
{
if(d.month<=7)
{
if(d.month%2==1)
{
if(d.day==31)
{
d.day=1;
++d.month;
}
else
{
++d.day;
}
}
else
{
if(d.day==30)
{
d.day=1;
++d.month;
}
else
{
++d.day;
}
}
}
else if(d.month>7)
{
if(d.month%2==0)
{
if(d.day==31)
{
d.day=1;
++d.month;
}
else
{
++d.day;
}
}
else
{
if(d.day==30)
{
d.day=1;
++d.month;
}
else
{
++d.day;
}
}
}
}
cout<<d.year<<"\t"<<d.month<<"\t"<<d.day<<"\t";
}
int distanceDate(Date& d1,Date& d2)
{
int m,n;
m=goday(d1);
n=goday(d2);
if((d2.year-d1.year)>=0)
{

if((d2.year-d1.year)%4==0)
return 1461*(d2.year-d1.year)/4+n-m;
if((d2.year-d1.year)%4==1)
{
if(d1.year%4==0&&d1.year%100!=0||d1.year%400==0)
return 1461*(d2.year-d1.year-1)/4+n-m+366;
else
return 1461*(d2.year-d1.year-1)/4+n-m+365;
}
if((d2.year-d1.year)%4==2)
{
if((d1.year%4==0&&d1.year%100!=0||d1.year%400==0)||((d1.year+1)%4==0&&(d1.year+1)%100!=0||(d1.year+1)%400==0))
return 1461*(d2.year-d1.year-2)/4+n-m+365+366;
else
return 1461*(d2.year-d1.year-2)/4+n-m+365+365;
}
if((d2.year-d1.year)%4==3)
{
if((d1.year%4==0&&d1.year%100!=0||d1.year%400==0)||((d1.year+1)%4==0&&(d1.year+1)%100!=0||(d1.year+1)%400==0)||((d1.year+2)%4==0&&(d1.year+2)%100!=0||(d1.year+2)%400==0))


return 1461*(d2.year-d1.year-3)/4+n-m+366+365+365;
else
return 1461*(d2.year-d1.year-3)/4+n-m+365+365+365;
}
}
else
{
if((d1.year-d2.year)%4==0)
return 1461*(d1.year-d2.year)/4+m-n;
if((d1.year-d2.year)%4==1)
{
if(d2.year%4==0&&d2.year%100!=0||d2.year%400==0)
return 1461*(d1.year-d2.year-1)/4+m-n+366;
else
return 1461*(d1.year-d2.year-1)/4+m-n+365;
}
if((d1.year-d2.year)%4==2)
{
if((d2.year%4==0&&d2.year%100!=0||d2.year%400==0)||((d2.year+1)%4==0&&(d2.year+1)%100!=0||(d2.year+1)%400==0))
return 1461*(d1.year-d2.year-2)/4+m-n+365+366;
else
return 1461*(d1.year-d2.year-2)/4+m-n+365+365;
}
if((d1.year-d2.year)%4==3)
{
if((d2.year%4==0&&d2.year%100!=0||d2.year%400==0)||((d2.year+1)%4==0&&(d2.year+1)%100!=0||(d2.year+1)%400==0)||((d2.year+2)%4==0&&(d2.year+2)%100!=0||(d2.year+2)%400==0))


return 1461*(d1.year-d2.year-3)/4+m-n+366+365+365;
else
return 1461*(d1.year-d2.year-3)/4+m-n+365+365+365;
}
}


}
int main()
{
Date d1,d2,d;
int m;
inputDate(d1);
inputDate(d2);
d1.print();
d2.print();
m=distanceDate(d1,d2);
cout<<"d2 distance d1 is:"<<"\t";
cout<<m<<endl;


cout<<"distance from the year's first day is:"<<"\t";
cout<<goday(d1)<<endl;
cout<<"The front of date d1 is:"<<"\t";
frontDate(d1);
cout<<"The date d1 is:"<<"\t";
backDate(d1);
cout<<"The back of date d1 is:"<<"\t";
backDate(d1);

}



全部回答

#ifndef CLASS_CLASS #define CLASS_CLASS

#include "Student.h"

class Class { private: Student s[50]; string speciality; int student_num; public: Class(char *s="", int n=0);

void Input(); void Print() const; double AverageOfSubject(int idx); void Sort(); };

bool cmpByAverage( Student& a, Student& b);

#endif // CLASS_CLASS

#ifndef GENDER_ENUM #define GENDER_ENUM

enum Gender {female, male};

void printGender(Gender g); void inputGender(Gender& g);

#endif // GENDER_ENUM

#ifndef STUDENT_CLASS #define STUDENT_CLASS

#include "Gender.h"

#include <iostream> #include <string> #include <algorithm> using namespace std;

#define Num 3

class Student { friend class Class; private: unsigned int sid; string name; Gender gender; double score[Num + 1]; public: Student() {} Student(unsigned int id, char* sn, Gender g, double s[]);

void Input(); void Print() const; double Average(); };

#endif // STUDENT_CLASS

#include "Class.h"

Class::Class(char *s, int n) :speciality(s), student_num(n) {}

void Class::Input() { cout << "Please enter speciality:\t"; getline(cin, speciality); cout << "Please enter student number:\t"; cin >> student_num; for (int i=0; i < student_num; ++i) s[i].Input(); }

void Class::Print() const { cout << speciality << "\t" << student_num << endl; for (int i=0; i < student_num; ++i) { cout << "No." << i + 1 << "\t"; s[i].Print(); } }

double Class::AverageOfSubject(int idx) { double sum = 0; for (int i = 0; i < student_num; ++i) sum += s[i].score[idx]; return sum /= student_num; }

void Class::Sort() { sort(s, s + student_num, cmpByAverage); }

bool cmpByAverage( Student& a, Student& b) { return a.Average() > b.Average(); } #include <iostream> using namespace std;

#include "Gender.h"

void printGender(Gender g) { if (g == female) cout << "female"; else if (g == male) cout << "male"; }

void inputGender(Gender& g) { char ch; cout << "Please enter gender:\t"; cin >> ch; if (ch == 'f') g = female; else if (ch == 'm') g = male; }

#include "Student.h" #include "Class.h"

void main() { Class c;//("computer science", 30); c.Input(); c.Print(); c.Sort(); } #include "Student.h"

#define Num 3

Student::Student(unsigned int id, char* sn, Gender g, double s[]):sid(id),name(sn), gender(g) { for (int i = 0; i < Num; ++i) score[i] = s[i]; }

void Student::Input() { cout << "Please enter sid:\t"; cin >> sid; cin.get(); cout << "Please enter name:\t"; getline(cin, name); cin.get(); inputGender(gender); cout << "Please enter 3 scores:\t"; for (int i = 0; i < Num; ++i) cin >> score[i]; }

void Student::Print() const { cout << sid << "\t" << name << "\t";// << gender; printGender(gender); for (int i = 0; i < Num; ++i) cout << "\t" << score[i] << "\t"; cout << endl; }

double Student::Average() { score[Num] = 0; for (int i = 0; i < Num; ++i) score[Num] += score[i]; score[Num] /= Num; return score[Num]; }

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
上海松江泗泾镇古楼路652号是小区吗?
谁帮我想想现代海军有什么战斗口号,最好是有
欧得隆生鲜超市方泰店地址在什么地方,想过去
CS优化命令问题
关于描写七月的古诗词,有没有描写七月的诗句?
现在油价还能降下来不
飞车快速等级?
问问最高等级是多少?
姐妹油条店怎么去啊,有知道地址的么
qq飞车宠物终极形态图片
SS怎么样鬼火才能打高DPS 暴击多少合格 SW级
为什么最近老厌烦身边的朋友?
中国移动通信南大街移动营业厅在哪里啊,我有
IE浏览器08问题
老人头是台湾的吗?苏州企鹅王服饰有限公司生
推荐资讯
湖南省常德市首富是谁?
刨根问底的意思二年级,人木三分是琴棋书画中
2人云南丽江行的费用?
QQ炫舞里 创了个舞团叫Top 皇族 请朋友们帮我
泡泡堂唰段对应、关于战绩和段。
三辆车同时到一个加油站加油,大卡车需要8分
QQ宠物贴心宝贝喂宠物消耗喂养品有顺序吗
粗心的的用英语怎么说,粗心用英语怎么说
星座可信吗?
谁可以邀请我加入家族
问个英语定语从句的问题
读书感到疲惫了,成绩上不去了怎么办?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?