![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
上機練習(xí)1 |
上機模擬試卷(1) (1) 改錯題: 函數(shù)fun的功能是:求出s所指字符串中最后一次出現(xiàn)t所指子字符串的地址,通過函數(shù)值返回,在主函數(shù)中輸出從此地址開始字符串,若未找到,則函數(shù)值為NULL. 例如:當字符串中的內(nèi)容為 abcdabfabcdx,t中的內(nèi)容為ab時,輸出結(jié)果為abcdx. 含有錯誤的源程序如下: # include <iostream.h> #include <string.h> char *fun(char *s, char *t) { char *p,*r,*a; a=Null; while(*s) { p=s;r=t; while(*r) if(r==p) {r++;p++} else break; if(*r==’\ p++; } return a; } main() { char s[100], t[100], *p; cout<<”Please enter string S:”; cin>>s; cout<<”Please enter substring t:”; cin>>t; p=fun(s,t); if(p) cout<<”The result is:”<<p; else cout<<”Not found!”; }
二:編程題: 建立一個類Array,動態(tài)生成數(shù)組,按數(shù)組元素后兩位上值大大小進行降序排序,數(shù)組中的每個數(shù)均是四位數(shù),具體如下: 1. 私有數(shù)據(jù)成員. int *a:指向根據(jù)len動態(tài)申請的數(shù)組空間 int len:有效數(shù)組元素的個數(shù) 2. 公有成員函數(shù): Array(int b[],int length):構(gòu)造函數(shù),使用數(shù)組b初始化a所指的動態(tài)數(shù)組,length初始化len void sort():按題意對動態(tài)數(shù)組中的元素進行排序 void print():輸出a所指向的數(shù)組 ~Array():析構(gòu)函數(shù), 釋放動態(tài)數(shù)組空間 3.在主函數(shù)中定義一個Array類的對象test,調(diào)用成員函數(shù)完成排序和輸出
|