同濟c++期末模擬題(word版)_第1頁
同濟c++期末模擬題(word版)_第2頁
同濟c++期末模擬題(word版)_第3頁
同濟c++期末模擬題(word版)_第4頁
同濟c++期末模擬題(word版)_第5頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、1、程序的功能是輸入你的出生日期,判斷你的生日是星期幾。要求定義一個時間類date,包括年,月,日3個私有數(shù)據(jù)成員,和三個公有成員函數(shù):void set(int y,int m,int d)用于設(shè)置數(shù)據(jù)成員年、月、日的值,int weekday()用于計算某個日期是星期幾。void display() 用來顯示結(jié)果。在主函數(shù)中讀入你的生日(年、月、日),調(diào)用成員函數(shù)設(shè)置數(shù)據(jù)成員,計算生日是星期幾,并顯示結(jié)果。2、程序的功能是判斷一個字符串是不是回文字符串。判斷一個字符串s是否是回文串要求編寫遞歸函數(shù)實現(xiàn),算法思想是:先判斷第1個字符和最后1個字符是否相等,若不等,則不是回文串,若相等,則遞歸的

2、判斷由第2個字符倒數(shù)第2個字符構(gòu)成的串是否是回文串,編寫遞歸函數(shù)int huiwen()實現(xiàn)判斷字符串s是不是回文,是返回1,不是,返回0。主函數(shù)中調(diào)用該函數(shù),對輸入的字符串進行判斷,并顯示判斷的結(jié)果。3、學(xué)生的信息包括學(xué)號char num6,成績 int score 和密碼字符串char key15。建立如下的字符菜單,根據(jù)用戶的選擇完成相應(yīng)的功能。1、建立學(xué)生檔案: 輸入學(xué)生人數(shù)n,然后依次輸入n個學(xué)生的信息,按成績從低到高的順序?qū)W(xué)生信息組織到鏈表或結(jié)構(gòu)體數(shù)組中(如圖所示)。2、 顯示所有學(xué)生:顯示所有學(xué)生的信息,其中密碼字符以*顯示,一個字符對應(yīng)一個*(如圖所示)。 3、 修改學(xué)生信息

3、:輸入學(xué)號,按照學(xué)號修改學(xué)生的成績和密碼字符串,再次顯示學(xué)生數(shù)據(jù)時,顯示修改后的信息。4、 退出:將學(xué)生數(shù)據(jù)保存到文件c:ksstudent.dat中并退出程序。(要求使用結(jié)構(gòu)體數(shù)組或者鏈表實現(xiàn))答案1. #include iostream.h#define sun 0#define mon 1#define tue 2#define wed 3#define thu 4#define fri 5#define sat 6class dateprivate:int year,month,day;public:void set(int y,int m,int d)year=y;month=m;d

4、ay=d;int weekday1();void display();int date:weekday1()int days212=31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31;int weekday=mon,i;for (i=1900;iyear;i+)weekday=(weekday+365)%7;if (i%400=0|i%4=0 & i%100!=0) weekday=(weekday+1)%7;if (year%400=0|year%4=0 & year %100!=0) for(i=1

5、;imonth;i+)weekday=(weekday+days1i-1)%7;elsefor(i=1;imonth;i+)weekday=(weekday+days0i-1)%7;for(i=1;iday;i+)weekday=(weekday+1)%7;return weekday;void date:display()cout你的出生日期是:year年month月day日 ;int w=weekday1();switch (w)case 0:cout星期天;break;case 1:cout星期一;break;case 2:cout星期二;break;case 3:cout星期三;bre

6、ak;case 4:cout星期四;break;case 5:cout星期五;break;case 6:cout星期六;break;coutendl;main()date a;int y,m,d,w;cout請輸入你的出生日期:ymd;a.set(y,m,d);w=a.weekday1();a.display();2#include iostream.h#include stdio.h#include string.hint huiwen(char s,int i,int j);void main()char s80;gets(s);int i=0;int j=i+strlen(s)-1; i

7、nt k= huiwen(s,i,j); if(k0) couthuiwenendl; else cout=j)return 1; if (si!=sj)return 0;elsereturn huiwen(s,i+1,j-1);3.#include iostream.h#include stdlib.h#include string.h#include stdio.hstruct studentchar num10;int score;char key15;struct student *next;struct student *create(int);void output(struct

8、student *head);void modify(struct student *head);void main()struct student *head;int n,choose;while(1)cout1.建立學(xué)生檔案endl;cout2.顯示所有學(xué)生endl;cout3.修改學(xué)生信息endl;cout4.退出endl;cout請輸入用戶選擇:choose;switch(choose)case 1: cout請輸入學(xué)生人數(shù):n;head=create(n);break;case 2: output(head);break;case 3: modify(head);break;case

9、 4: system(cls);exit(0);struct student *create(int n)struct student *head=null,*p,*q,*newnode;int i;for(i=1;i=n;i+)newnode=new student;cout請輸入學(xué)生信息:endl;coutnewnode-num;coutnewnode-key;coutnewnode-score;newnode-next=null;if (head=null)head=newnode;elsep=head;while(p!=null & newnode-scorep-score)q=p;p=p-next;if(p=head)newnode-next=head;head=newnode;elseq-next=newnode;newnode-next=p;return head;void output(struct student *head)int i;struct student *p;cout顯示所有學(xué)生:endl;cout學(xué)號成績密碼串endl;p=head;while(p!=null)coutnumtscorekeyi!=0)cout*;i+;coutnext;v

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論