c++第一次作業
一、程式設計分析題。
1.分析程式寫出結果:x,y=15,25
x,y=15,25
x,y=15,25
x,y=14,26
2.分析程式寫出結果:1,a,4.5#include
using
namespace std;
voidf1(
int x,
int y)
voidf2(
int& x,
int& y)
voidf3(
int* x,
int* y)
intmain()
2,b,3.5
3.分析程式寫出結果:a[0][0]=2#include
using
namespace std;
voidf(
int,
char
,double
=3.5);
intmain()
voidf(
int a,
char b,
double c)
a[0][1]=2
a[1][0]=6
a[1][1]=6
4.分析程式寫出結果:2#include
using
namespace std;
intmain()
,};int
*pa[2]
;//(*p)[2] 是乙個陣列指標,指向含2個元素的一維陣列,定義了乙個指標陣列,*p[2]該陣列中每個元素(共有n個元素)都是乙個指標,
//至於每個指標所指向的位址就要看後面的程式定義了,[ ]優先順序高,先與p結合成為乙個陣列,再由int*說明這是乙個整型指標陣列,它有n個指標型別的陣列元素。
pa[0]
=a[0
];pa[1]
=a[1];
for(
int i=
0;i<
2;i++
)for
(int j=
0;j<
2;j++
) cout<<
"a["
<"]["
<"]="
<<
*pa[i]
<}
二、程式設計題。#include
using
namespace std;
intfun
(char*,
char*)
;int
main()
intfun
(char
*s1,
char
*s2)
1、定義結構體型別「三角形」,編寫函式分別實現:(1)輸入三角形三邊邊長,(2)判斷是否構成三角形,(3)在main函式中進行測試。
2、定義函式模板和主函式實現兩個數值、兩個字串的交換。#include
#include
using
namespace std;
class
c********
;void c********::
init
(int a_,
int b_,
int c_)
float c********::
area()
intmain()
3、定義過載的函式模板和主函式分別實現2個數值,3個數值型資料求最大值。#include
#include
using
namespace std;
void
swap
(int
&a,int
&b,string &p,string &q)
intmain()
4、定義函式模板:(1)在陣列a的前n個元素中查詢某個元素k,如果找到就返回下標,否則返回-1表示失敗,(2)對於找到的元素統計他出現的次數,(3)在main函式中定義兩組資料測試上述模板。#include
using
namespace std;
intmax
(int a,
int b)
intmax
(int a,
int b,
int c)
intmain()
#include
using
namespace std;
intsearch
(int a,
int n,
int x)
;int
frequency
(int a,
int n,
int x)
;int
main()
cout<<
"please input the number;"
>x; k=search
(a,10
,x);
p=frequency
(a,10
,x);
cout<<
"the frequency:"
=0) cout<<
"the number:"
cout<<
"no found"
}int
frequency
(int a,
int n,
int x)
}return count;
}int
search
(int a,
int n,
int x)
if(flag==0)
return-1
;}
c 第一次作業
要求 計算 的注釋行,行,空行和總行數。步驟解析 先開啟檔案,讀取檔案,因為注釋行開頭以 或者 開頭,所以有 或者 的行為注釋行。空行就是什麼都沒有的,為空的。行就是有 的,實現這些功能的過程中需要用到trim這個函式。如下 using system using system.collections...
c 第一次作業
using system using system.collections.generic using system.linq using system.text using system.threading.tasks using system.io using system.text.regul...
C 第一次作業
c 作業1 編寫乙個程式,要求從螢幕輸入你的名字和年齡,在螢幕顯示你的名字和你明年的年齡。include include using namespace std intmain 在螢幕上輸入兩個整數,求兩個數的差,並將結果運算出來。include include using namespace st...