题目内容 (请给出正确答案)
[主观题]

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

【说明】

设计一个日期类Date包括年、月、日等私有数据成员。要求实现日期的基本运算,如某日期加上天数、某日期减去天数、两日期相差的天数等。

在Date类中设计如下重载运算符函数:

Date operator + (int days) : 返回某日期加上天数得到的日期。

Date operator - (int days) : 返回某日期减去天数得到的日期。

int operator - (Date&b): 返回两日期相差的天数。

【程序】

include<iostream.h>

int day tab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},

{31,29,31,30,31,30,31,31,30,31,30,31}};

//day_tab二维数组存放各月天数,第一行对应非闰年,第二行对应闰年class Date

{

int year, month, day //年,月,日

int leap(int); //判断是否闰年

int dton(Date&)

Date ntod(int)

public:

Date() { }

Date (int y, int mint d) I year = y; month = m; day = d;}

void setday(intd){day = d;}

void setmonth(int m) {month = m;}

void setyear(int y) {year =y;}

int getday() {return day;}

int getmonth() {return month:}

int getyear() {return yea;}

Date operator + (int days) //+运算符重载函数

{

static Date date;

int number =(1)

date = ntod(number)

return date

}

Date operator - (int days) //-运算符重载函数

{

staffs Date date;

int number=(2);

number - = days;

date = ntod(number)

return date;

}

int operator - (Date &b) //-运算符重载函数

{

int days=(3);

return days;

}

void disp()

{

cout<<year<<"."<<month<<". "<<day<<endl;

}

};

int Date: :leap(int year)

if((4)) //是闰年

return 1; //不是闰年

else

return0:

}

int Date:: dton(Date &d) //求从公元0年0月0日到d日期的天数

{

inty,m,days =0;

for(y=1;y<=d. year;y++)

if((5))days+ =366; //闰年时加366天

else days + = 365; //非闰年时加365天

for(m =0;m<d. month-1;m++)

if((6))

days += day_tab[1] [m];

else

days +=day_tab[0] [m];

days + = d. day;

return days;

}

Date Date::ntod(intn) //将从元0年0月0日的天数转换成日期

{

int y=1,m = 1,d,rest = n,lp;

while(1)

{ if(leap(y))

if(rest<= 366) break;

else rest - = 366;

else //非闰年

if(rest = 365 ) break;

else rest-=365;

提问人:网友aazyzyaa 发布时间:2022-01-06
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内…”相关的问题
第1题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明] 本程序中预设了若干个用户名和

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

[说明]

本程序中预设了若干个用户名和口令。用户输入正确的用户名后,可以查找对应的口令,一旦输入结束标记“end”,程序结束。

[C++程序]

include <iostream. h>

include <string. h>

class User

{ protected:

char user[10];

char pass[7];

public:

User(char[ ],char[]);

(1) {return user;}

(2) {return pass;}

};

User::User(char u[],char p[])

{ strcpy(user,u);

strcpy(pass,p); }

void main()

{ User ua[]={User("Li","123456"),User("wang","654321"),User("Song","666666")

char name[10];

while(1)

cout< < "输入用户名:";

cin> >name;

if((3)= =0) break;

for(int i=0;i<3;i+ +)

if(strcmp(name,ua[i].getuser()) = =0){

cout< <"密码:" < < ua[i].getpass() < <endl;

(4);

if((5))cout< <"该用户不存在!" < <endl;

}

}

点击查看答案
第2题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序输出一个矩形面积,

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

[说明]

下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。

[C++程序]

include <iostream.h>

class crop_assessment

{

int actual_crop;

int ideal_crop;

public:

void set(int in_actual,int in_ideal)

{

actual crop=in_actual;

ideal_crop=in_ideal;

}

int get_actual_crop(void){ (1) ;}

int get_ideal_crop(void){ (2) ;)

};

Class lot_size

{

int length;

int width;

(3) crop;

public:

void set(int 1,int w,int a,int i)

{

length=1;

width=w;

crop.set(a,i);

}

int get_area(void){return length*width;}

int get_data(void){return (4) ;}

int get_data2(void)freturn (5) ;}

}

int main()

{

Los_size small,medium;

small.set(5,5,5,25);

medium.set(10,10,10,50);

cout<<"For a small lot of area"<<smallget_area()<<“\n”;

cout<<"the actual crops are$"<<small.get_data2()<<"\n";

cout<<"and ideal crops are$”<<small.get_data()<<"\n";

cout<<"For a medium Lot of area"<<medium.get area()<<:\n”;

cout<<"the actual crops are$"<<medium.get_data2()<<"\n";

cout<<"and ideal crops are$"<<medium.get_data()<<"\n";

return 0;

}

点击查看答案
第3题
阅读以下说明和C++代码,将应填入____处的语句或语句成分写在答题纸的对应栏内。

某数据文件students.txt的内容为100名学生的学号和成绩,下面的程序将文件中的数据全部读入对象数组,按分数从高到低进行排序后选出排名前30%的学生。【C++代码】

阅读以下说明和C++代码,将应填入____处的语句或语句成分写在答题纸的对应栏内。	某数据文件stu

点击查看答案
第4题
阅读以下说明和C++抖程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 下面程序的功能是计

阅读以下说明和C++抖程序,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

下面程序的功能是计算并输出某年某月的天数。

【C++程序】

include<iostream>

using namespace std;

(1) Month{Jan,Feb,Mar,Art,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};

class Date{

public:

Date(int year,Month m_month){

(2) =year;

if (m_month<Jan‖m_month>Dec) month=Jan;

else month=m_month;

};

~Date(){};

bool IsLeapYear(){

return ((year%4==0 && year%1001!=0)‖year%400==0);

};

int CaculateDays(){

switch((3) ){

case Feb:{

if((4) )return29;

e1Se return 28;

}

case Jan:case Mar:case May:case Jul:case AUg:case Oct:

case Dec:retllrn 31;

case Apr:case Jun:Case Sep:case Nov:roturu30;

}

};

private:

int year;

Month month;

};

void main(){

Date day(2000,Feb);

tout<<day. (5) ();

}

点击查看答案
第5题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】下面程序的功能是计算并输出某年

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

【说明】

下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year()能够判断是否是闰年。

【C++程序】

include < iostream >

using namespace std;

(1) Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };

class Date {

public:

Date(int year, Month m_ month) {

this→year = year;

if((2) ) month: Jan;

else month = m_ month;

};

~Date(){};

bool IsLeap Year() {

return ((year%4= =0 &&year% 100 ! =0)|| year%400= =0);

};

int CaculateDays() {

switch(m_month ) {

case (3) ;{

if (4) return 29;

else return 28;

}

case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31;

case Apr: case Jun: case Sop: case Nov: return 30;

}

}

private:

int year;

Month month;

};

void main() {

Date day(2000,Feb);

cout < <day. (5) ();

}

点击查看答案
第6题
●试题六 阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 设计一个

●试题六

阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

设计一个类模板Sample用于对一个有序数组采用二分法查找元素下标。

【C++程序】

#include<iostream.h>

#define Max 100∥最多元素个数

template<class T>

class Sample

{

T A[Max]:∥存放有序数序

int n:∥实际元素个数

public

Sample(){}∥默认构造函数

Sample(T a[],int i);∥初始化构造函数

int seek(T c);

void disp()

{

for(int i=0;i<n;i++)

cout<<A[i]<<"";

cout<<end1:

}

};

template<class T>

Sample<T>::Sample(T a[],int i)

{

n=i;

for(intj=0;j<i;j++)

(1) ;

}

template<class T>

int Sample<T>::seek(T c)

{

int low=0,high=n-1,mid;

while((2) )

{

mid=(low+high)/2;

if((3) )

return mid;

else if((4) )

low=mid+l;

else

(5) ;

}

return-1;

}

void main()

{

char a[]="acegkmpwxz";

Sample<char>s(a,1。);

cout<<"元素序列:";s.disp();

cout<<"元素′g′的下标:"<<s.seek(′g′)<<endl;

}

点击查看答案
第7题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】 设计一个类模板SamPle用于对一

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

【说明】

设计一个类模板SamPle用于对一个有序数组采用二分法查找元素下标。

【C++程序】

include < iostream. h >

define Max 100 //最多元素个数

template < class T >

class Sample

{

T A[Max]: //存放有序数序

int n: //实际元素个数

public

Sample() { } //默认构造函数

Sample(T a[] ,int i); //初始化构造函数

int seek(T c);

void disp()

{

for(int i=0;i <n;i ++)

cout<<A[i] <<" ";

cout<<endl:

} } template < class T >

Sample <T>: :Sample(T a[ ],int i)

{

n=i:

for(intj =0;j < i;j ++ )

(1);

}

template < class T >

int Sample < T >:: seek(T c)

{

int low =0,high = n-1 ,mid;

while((2))

{

mid = (low + high)/2;

if((3))

return mid;

else if((4) )

low=mid+|;

else

(5);

}

return-1;

}

void main()

{

char a[ ] ="acegkmpwxz";

Sample < char > s(a, 1);

cout<<"元素序列:" ;s. disp();

cout<<"元素'g'的下标:"<<s. seek('g') <<endl;

}

点击查看答案
第8题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内 [说明] 以下程序的功能是计算三角形、

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内

[说明]

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

程序由4个类组成:类Triangle,Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。

[C++程序]

include<iostream.h>

include<math.h>

class Figure{

public:

virtual double getArea()=0; //纯虚拟函数

};

class Rectangle: (1) {

protected:

double height;

double width;

public:

Rectangle(){};

Rectangle(double height,double width){

This->height=height;

This->width=width;

}

double getarea(){

return (2);

}

};

class Square: (3)

public:

square(double width){

(4);

}

};

class triangle: (5) {

double la;

double lb;

double lc;

public:

triangle(double la,double lb,double lc){

this->la=la;thiS->ib;this->lc;

}

double getArea(){

double s=(la+lb+lc)/2.0;

return sqrt(s*(s-la)**(s-lb)*(s-lc));

}

};

viod main(){

figure*figures[3]={

new triangle(2,3,3),new Rectangle(5,8),new Square(5)};

for(int i=0; i<3;i++){

cout<<"figures["<<i<<"]area="<<(figures)->getarea()<<endl;

}

}

};

点击查看答案
第9题
●试题六 阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。 【说明】 以下程序

●试题六

阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。

【说明】

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口

【C++程序】

#include<iostream.h>

#include<math.h>

class Figure{

public:

virtual double getArea()=0:∥纯虚拟函数

};

class Rectangle: (1) {

protected:

double height;

double width;

public:

Rectangle(){};

Rectangle(double height,double width){

this->height=height;

this->width=width;

}

double getArea(){

return (2) ;

}

};

class Square: (3) {

public:

Square(double width){

(4) ;

}

};

class Triangle: (5) {

double la;

double Ib;

double lc;

public:

Triangle(double la,double lb,double lc){

This->la=la;this->lb=lb;this->lc=lc;

}

double getArea(){

double s=(la+lb+±c)/2.0;

return sqrt(s*(s-1a)*(s-1b)*(s-1c));

}

};

void main(){

Figure*figures[3]={

new Triangle(2,3,3),new Rectangle(5,8),new SqUare (5) );

for (int i=0;i<3;i++){

cout<<"figures["<<i<<"]area="<<(figures[i])->getArea()<<endl;

}

}

点击查看答案
第10题
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。[说明] 以下程序的功能是实现堆栈的一些

阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。

[说明]

以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。

[C++程序]

include "stdafx. h"

include <iostream, h>

eonst int maxsize = 6;

class stack {

float data[ maxsize];

int top;

public:

stuck(void);

~ stack(void);

bool empty(void);

void push(float a);

float pop(void);

};

stack: :stack(void)

{ top =0;

cout < < "stack initialized." < < endl;

}

stack:: ~stack(void) {

cout < <" stack destoryed." < < endl;

bool stack:: empty (void) {

return (1);

void stack: :push(float a)

if(top= =maxsize) {

cout < < "Stack is full!" < < endl;

return;

data[top] =a;

(2);

}

float stack:: pop (void)

{ if((3)){

cout< < "Stack is undcrflow !" < < endl;

return 0;

(4);

return (5);

}

void main()

{ stack s;

coat < < "now push the data:";

for(inti=l;i< =maxsize;i+ +) {

cout< <i< <" ";

s. push(i);

}

coat < < endl;

cout< < "now pop the data:";

for(i = 1 ;i < = maxsize ;i + + )

cout< <s. pop()< <" ";

}

点击查看答案
第11题
阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。说明 以下程序的功能是计算三

阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。

说明

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。

c++程序

include <iostream.h>

inclule <math.h>

class Figure {

public:

virtual double getArea()= 0; // 纯虚拟函数

};

class Rectangle: (1) {

protected:

double height;

double width;

public:

Rectangle() { };

Rectangle(double height, double width) {

this->height = height;

this->width = width;

}

double getArea() {

return (2) ;

}

class Square: (3) {

public:

Square(double width) {

(4) ;

}

};

class Triangle: (5) {

double la;

double lb;

double lc;

public:

Triangle(double la, double lb, double lc) {

this->la = la; this->lb ='lb; this->lc = lc;

}

double getArea() {

double s = (la+lb+lc)/2.0;

return sqrt(s*(s-la)*(s-lb)*(s-lc));

} }; void main() {

Figure* figures[3] = {

new Triangle(2,3,3), new Rectangle(5,8), new Square(5)};

for (int i = 0; i < 3; i++) {

com << "figures[" << i << "] area =" << (figures[i])->getArea0 << endl;

}

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信