C 第三次上機

2021-07-10 18:27:46 字數 2098 閱讀 6450

題目一:

假設有乙個字串strfilename=@"d:\c#程式設計\實驗3\myfile.txt".使用字串方法,取出路徑中的檔名"myfile.txt".(要求至少想出三種方法實現)。

(1)

using system;

using system.collections.generic;

using system.linq;

using system.text;

public static string getfilename(string strfilenme)

}}

(2)

using system;

using system.collections.generic;

using system.linq;

using system.text;

public static string getfilename(string strfilenme)

}}

(3)

using system;

using system.collections.generic;

using system.linq;

using system.text;

public static string getfilename(string strfilenme)

return str;}}

}

題目二:

實驗stringbuilder類。定義乙個靜態成員方法,該方法實現字串反轉。如reconvert("6221982")返回值為2891226.自行設計程式驗證上述方法正確性。

using system;

using system.collections.generic;

using system.linq;

using system.text;

public static string reconvert(string str)

return strr.tostring();}}

}

題目三:

輸入學號和姓名,對不存在的學號加到hashtable類的例項中,對存在學號給出提示,結束輸入後,輸出學號為奇數的所有學生。

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.collections;

else

}console.writeline("輸出學號為奇數的所有學生");

foreach(dictionaryentry item in hst)

,",item.key,item.value);}}

console.readkey();}}

}

題目四:

輸入某人出生日期(以字串方式輸入,如1987-4-1)使用datetime和timespan類

(1)計算此人的年齡

(2)計算從現在到其60周歲期間,總共多少天。

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.collections;

歲", age);

datetime dt = new datetime(year, mouth, day);

year += 60;

datetime dt2 = new datetime(year, mouth, day);

timespan ts = dt2 - datetime.now;

console.writeline("計算從現在到其60歲期間,總共有天", ts.days.tostring());

console.readkey();}}

}

c 第三次上機實驗

一 問題及 檔名稱 1.cpp 作 者 梁世雄 完成日期 2016 年04 月 10 日 版 本 號 v1.0 對任務及求解方法的描述部分 求個人所得稅及稅後收入,運用if語句的巢狀程式設計序。輸入描述 輸入dsalary 問題描述 不同階段的工資稅率不同。程式輸出 輸出個人所得稅dtax及稅後收入...

C 第三次上機實驗

一 問題及 靜態成員應用 time 類 檔名稱 c 第三次實驗 類和物件2.cpp 作 者 郭宇輝 完成日期 2016 年 4 月 22 日 版 本 號 v1.0 對任務及求解方法的描述部分 靜態成員應用 輸入描述 無 問題描述 設計含有靜態資料成員和成員函式的time類。靜態資料成員是類中所有的物...

PTA第三次上機

include include include using namespace std class polygon int perimeter 計算多邊形邊長 void display 輸出多邊形邊數和周長 int reachsidelen int polygon perimeter return ...