同濟大學C mooc第12講 檔案

2021-10-12 13:00:00 字數 3212 閱讀 8722

同濟大學c++mooc第12講

沒想到我也會被催更hhh

你們要的12講和13講來了哦

第12講

編寫程式,從鍵盤輸入一串字元,要求將該串字元的倒序串先寫入到檔案f1.txt中,然後再將原字串的內容接到該檔案的末尾。例如,假設從鍵盤輸入的字串為「how do you do?」,則檔案f1.txt的內容為:

?od uoy od wohhow do you do?

**片.

// 

#include "iostream"

#include

#include

#define n

20using namespace std;

int main()

gets_s

(b);

int j =0;

for(int i =

strlen

(b)-

1;i >=

0;i--

)for

(int i =

0; i <

strlen

(b); i++

)fclose

(fp)

; fp =

fopen

("f1.txt"

,"a");

if(fp ==

null

)fputs

(b, fp)

;fclose

(fp)

; fp =

fopen

("f1.txt"

,"r");

while(!

feof

(fp)

)system

("pause");

return(0

);}

**片.

// 

#include "iostream"

#include

#include

#define n

10using namespace std;

int main()

int m =

0, b =

0, c =0;

for(int i =

0; i <

n; i++

)fclose

(fp)

; cout << m <<

' '<< b <<

' '<< c;

system

("pause");

return(0

);}

將從鍵盤輸入的n個學生的學號和成績存入到檔案student.dat中。再從檔案中讀取學生的資訊,求出最高分、最低分和總分。n可通過符號常量自行定義大小。

**片.

// 

#include "iostream"

#include

#include

#define n

3using namespace std;

struct student

;int main()

for(int i =

0; i <

n; i++

)fclose

(fp)

; fp =

fopen

("student.dat"

,"rb");

if(fp ==

null

) int max =

0, min =

999,sum =0;

fread

(t,sizeof

(t),

1, fp)

;for

(int i =

0; i <

n; i++

) cout <<

"最高分為:"

<< max <<

" "<<

"最低分為:"

<< min <<

"總分為:"

<< sum;

system

("pause");

return(0

);}

編寫程式,從鍵盤輸入一字串,要求將其中的大小寫字母互相轉換後寫入檔案。

**片.

// 

#include "iostream"

#include

#include

#define n

20using namespace std;

int main()

gets_s

(b);

for(int i =

0; i <

strlen

(b); i++

)fputs

(b, fp)

;fclose

(fp)

; fp =

fopen

("f1.txt"

,"r");

while(!

feof

(fp)

)system

("pause");

return(0

);}

i(73) (32)l(108)o(111)v(118)e(101) (32)c(67)h(104)i(105)n(110)a(97)

注意:空格也是有效字元。

**片.

// 

#include "iostream"

#include

#include

#define n

20using namespace std;

int main()

gets_s

(b);

fputs

(b, fp)

;fclose

(fp)

; fp =

fopen

("f1.txt"

,"r");

int i =0;

while

(i <

strlen

(b))

system

("pause");

return(0

);}

同濟大學課程設定

同濟大學課程設定 公共基礎課必修 100383電腦科學導論 13.051 公共基礎課必修 100384高階語言程式設計 112.034 公共基礎課必修 100386高階語言程式設計實驗 111.034 公共基礎課必修 122004高等數學 b 上 15.085 公共基礎課必修 580006物理實驗 ...

同濟大學C mooc 第三講 第四講

同濟大學c moooc第3 4講 第三講以下程式的功能是求兩個非0整數相除的商和餘數。程式有幾處錯誤,試找出它們加以修改,並上機驗證修改結果。片.include iostream using namespace std int main else cout 商 r1 餘數 r2 endl syste...

同濟大學博導陳明 解讀中國製造2025

本文講的是同濟大學博導陳明 解讀中國製造2025,中國製造2025已經成為製造業發展熱點,受到產業界的普遍關注,但中國製造2025與工業4.0有何區別?中國製造業2025的內涵又在 近日,來自同濟大學博士生導師陳明在以 智慧型製造 智慧型管理 為主題的用友u8 網際網路 產業聯盟峰會為我們解讀了中國...