不太理解的題
1.#include
using namespace std;
char abc( char *);
char abc(char &);
void main()
}char abc(char *s)
char abc(char &s)
答案:cf
2.#include
class t
; static void display(t c)
;int t::b=5;
void main()
a. a=3 b=13 b. a=6 b=11 c. a=6 b=19 d. a=3 b=8
a=5 b=13 a=8 b=19 a=8 b=19 a=6 b=13
答案:c
3.以下是運輸公司對所運貨物計費的程式。
設每公里每噸的基本運費為p,貨物重量為w,總運輸里程在某段中的里程為δs,折扣為d,則該段運費為:p*w*δs*(1-d)。總費用為各段費用之和,採用不加break的switch語句。
int main()
cout<<"運輸單價:"< cout<<"折扣後運費:"< return 0;
}運輸公司是怎樣分段的?並給出各段的折扣率。,設輸入運輸單價、重量和里程為0.5 40 4300,輸出結果是什麼?
答案:分段與運費打折情況如下:
s<250不打折扣
250<=s<5002%折扣
500<=s<10005%折扣
1000<=s<2000 8%折扣
2000<=s<3000 10%折扣
3000<=s15%折扣
輸出結果:
運輸單價:0.5 重量:40 里程:4300
折扣後運費:77900
容易錯的題
1.#include
class a
a(a &a)
void print();
void main()
答案:2 1 不是 1 2
2.#include
void main()
cout<<"i, s="<}答案:15,56 不是12,42(因為i又加了乙個1才退出迴圈的啊!)
3. 輸入10個數,用「選擇法」將其按降序排列,然後輸出。
#include
void main()
for(i=0;i<10;i++)
cout< cout<3、輸出非波那契數列的前20項,每項占用6個字元的寬度,每行輸出5個數。該數列的通項公式為:a1=1,a2=1,an=an-1+an-2 (n>=3)。
#include
#include
void main()
}#include
void main()
; cout< for(int i= 2 ;i<20;i++)
4、輸入乙個自然數,判斷其是否為素數。
#include
int f1(int n);
void main()
int f1(int n)
return f;}
5.下面程式在一組數中查詢指定資料,請填空完善它。
#include
int search(int a,int n,int k)
void main()
; int x,p;
cout<<"請輸入要查詢的資料:";
cin>>x;
p=search(b,10,x);
if ( p==1 )
cout<<"位置為:"< else
cout<<"沒找到!" ;
}6. 編寫乙個函式模板「countarray」,用於統計一維陣列中某個指定值的出現次數。如對於一維整型陣列:
int a=,呼叫此模板函式可統計出陣列a中,「5」出現的次數為「2」。
template
int coutnarray(t a,int n,t x)
return count;
}7. 現有complex類用於描述複數,其部分**如下:
class complex
};(1) 用友元過載+運算子
complex operator+(complex &a,complex &b)
(2) 用友元過載-運算子
complex operator+(complex &a,double &d)
(3) 用友元過載《運算子
ostream & operator<<(ostream out,const complex &a)
8#include
class a
a(a &a)
void print();
void main()
{ a a(1),b(a);
程式設計題型別總結
求和類 1.計算s 1!2!3!4!n s 0k 1 input n to n for i 1 to n k k i s s k endfor s2.求 sum 0 for i 1 to 21 step 2 sum sum i 3 endfor sum sum 3.有一分數序列,求前20項之和 m ...
程式設計題型別總結
求和類 1.計算s 1!2!3!4!n s 0k 1 input n to n for i 1 to n k k i s s k endfor s2.求 sum 0 for i 1 to 21 step 2 sum sum i 3 endfor sum sum 3.有一分數序列,求前20項之和 m ...
程式設計題型別總結
求和類 1.計算s 1!2!3!4!n s 0k 1 input n to n for i 1 to n k k i s s k endfor s2.求 sum 0 for i 1 to 21 step 2 sum sum i 3 endfor sum sum 3.有一分數序列,求前20項之和 m ...