freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

cc語言期末復(fù)習(xí)含完整答案-資料下載頁

2025-06-09 21:23本頁面
  

【正文】 i) 。 //通過函數(shù)名調(diào)用print_float,實(shí)參為pi f_p = print_float 。 //f_p指向print_float f_p(pi) 。 //通過f_p調(diào)用print_float,實(shí)參為pi}10. 根據(jù)所給注釋完成程序。include void main(){ int array2[2][3]={{11,12,13},{21,22,23}}。 //聲明二維int型數(shù)組array2 for(int i=0。i2。i++){ cout *(array2+i) 或 array2[i] endl。 //輸出數(shù)組array2第i行的首地址 for(int j=0。j3。j++){ cout *(*(array2+i)+j) 或 array[i][j] 。 //輸出數(shù)組array2第i行元素值 } coutendl。 }}五、程序改錯(cuò)題 注意:不得增行或刪行,也不得更改程序的結(jié)構(gòu)。1. 函數(shù)fun的功能是:計(jì)算整數(shù)num各位上的數(shù)字之和。請指出錯(cuò)誤所在的行號,并改正。1include 2long fun (long num){3/************found************/4 long k=05 do{6 k += num%10 。7/************found************/8 num \= 10 。9 } while(num)。10/************found************/11 return num。12}13int main( ){14long n 。15 printf(\nPlease enter a number:)。 16/************found************/17scanf(%ld,n)。18 printf(\n%ld\n,fun(n))。19 return 0。20}4 long k=0。8 num/=10。11 return k17 scanf(“%ld”,amp。n)。2. 函數(shù)fun的功能是:將p所指字符串中的所有字符復(fù)制到b中,要求每復(fù)制三個(gè)字符之后插入一個(gè)空格。例如,在調(diào)用fun函數(shù)之前給a輸入字符串:ABCDEFGHIJK,調(diào)用函數(shù)之后,字符數(shù)組b中的內(nèi)容則為:ABC DEF GHI JK。含有錯(cuò)誤的程序如下:include void fun(char *p, char *b){ int i, k=0。 while(*p) { i=1。 while( i3 amp。amp。 *p ) { b[k]=p。 k++。 p++。 i++。 } if(*p) { b[k++]= 。 } } b[k]= 39。39。\039。39。}main(){ char a[80],b[80]。 printf(Enter a string: )。 gets(a)。 printf(The original string: )。 puts(a)。 fun(a,b)。 printf(\nThe string after insert space: )。 puts(b)。 printf(\n\n)。}1. while( i3 amp。amp。 *p ) 改為 while( i=3 amp。amp。 *p ) 2. b[k]=p。 改為 b[k]=*p。 3. b[k++]= 。 改為 b[k++]=39。 39。 4. b[k]= 39。39。\039。39。 改為 b[k]= 39。\039。 3. N個(gè)有序整數(shù)列已放在一維數(shù)組中,下列給定程序中函數(shù)fun的功能是:利用折半查找算法查找整數(shù)m在數(shù)組中的位置。若找到,則返回其下標(biāo)值,反之,則返回-1。提示:折半查找的基本算法是:每次查找前先確定數(shù)組中待查的范圍,low和high,然后把m與中間位置(mid)中元素的值進(jìn)行比較,如果m的值大于中間位置元素中的值,則下一次的查找范圍放在中間位置之后的元素中,反之,下一次的查找范圍落在中間位置之前的元素中。直到lowhigh,查找結(jié)束。含有錯(cuò)誤的程序如下:#include define N 10void fun (int a[ ], int m) { int low=0, high=N1, mid。 while (low=high) { mid=(low+high)/2。 if(m=a[mid]) high=mid1。 else if (m=a[mid]) low=mid+1。 return (mid)。 } return (1)。 } main () { int i, a[N]={3,4,7,9,13,45,67,89,100,180}, k, m。 printf (“a數(shù)組中的數(shù)據(jù)如下:”)。 for (i=0。 iN。 i++) printf (“%d”, a[i])。 printf (“Enter m: “)。 scanf(“%d”,amp。m)。 k=fun (a, m) if (k=0) printf(“m=%d,index=%d\n”, m,k)。 else printf (“Not be found!\n”)。 }1.void fun (int a[ ], int m) 改為 int fun (int a[ ], int m) 2.if(m=a[mid]) 改為 if(ma[mid]) 3.else if (m=a[mid]) 改為 else if (ma[mid]) 4.return (mid)。 改為 else return (mid)。六、編程題1. 編寫一個(gè)函數(shù),統(tǒng)計(jì)出具有n個(gè)元素的一維數(shù)組中大于等于所有元素平均值的元素個(gè)數(shù)并返回它。 int Count(double a[], int n)。 //此為該函數(shù)的聲明int count(double a[], int n){ int i,num=0。 double sum=0,avg。 for(i=0。in。i++) sum+=a[i]。 avg=sum/n。 for(i=0。in。i++) if(a[i]=avg) num++。 return num。}2. 定義函數(shù)int count(char *str),統(tǒng)計(jì)一個(gè)英文句子中字母的個(gè)數(shù),在主程序中實(shí)現(xiàn)輸入、輸出。int count(char *str){ int i,num=0。 for(i=0。str[i]!=39。\039。i++) { if((str[i]=39。a39。amp。amp。str[i]=39。z39。)||(str[i]=39。A39。amp。amp。str[i]=39。Z39。)) num++。 } return num。}3. 定義Boat和Car兩個(gè)類,二者都有重量(weight)屬性,定義二者的一個(gè)友元函數(shù)totalWeight(),計(jì)算二者的重量和。在主程序中測試該函數(shù)。includeincludeint count(double a[], int n)。int count(char *str)。class Boat。class Car。class Boat{private: int weight。public: Boat(int w) { weight=w。 } friend int totalWeight(Boat b,Car c)。}。class Car{private: int weight。public: Car(int w) { weight=w。 } friend int totalWeight(Boat b,Car c)。}。int totalWeight(Boat b,Car c){ return +。}void main(void){ double a[10]={,,,}。 printf(%d,count(a,10))。 char str[20]。 gets(str)。 printf(%d,count(str))。 Boat b(3)。 Car c(5)。 printf(%d,totalWeight(b,c))。}4. 完成復(fù)數(shù)的+,—運(yùn)算符重載,其運(yùn)算符重載的聲明函數(shù)如下,請完成+,運(yùn)算符的重載函數(shù)的定義并在主函數(shù)中測試。includeiostreamusing namespace std。class plex {public: plex(double r=,double i=){real=r。imag=i。} plex operator + (plex c2)。 friend plex operator (plex c1,plex c2)。void display()。 // 輸出復(fù)數(shù)private: double real。 double imag。 }。 第 23 頁 共 23 頁
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)教案相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1