2008年5月19日 星期一

簡易物件繼承

程式目的:利用類別繼承設計一個完整 物件導向c++程式,可以從鍵盤輸入學生 學號
性別,國文,英文,數學 成績,並在檔案輸出每位學生 資料

程式碼:
#include  //基本輸入輸出 
#include  //輸出檔案用 
#include   //處理string用 
using namespace std;

class personal  //個人資料 
{
private :
string name;       //姓名 
string id;         //學號 
char sex;          //性別 
public :
void setpersonal(string n,string i,char s) //設定資料 
{
name = n;
id = i;
sex = s;               
}
string Name() { return name;}
string Id() { return id;}
char Sex() {return sex;}
};
class student : public personal //個人成績 
{
private :
int chinese;   // 中文 
int english;   // 英文 
int math;      // 數學 
public :
void setstudent(string n,string i,char s,int c,int e,int m) //設定資料 
{
chinese = c;
english = e;
math = m;
setpersonal(n,i,s);    
}
int getChinese() { return chinese; }
int getEnglish() { return english; }
int getMath() { return math; }
};

int main() {
student st;
string name,id;
char sex;
int cht,eng,math;
// 使用者輸入資料 
cout << "Name:";
cin >> name;
cout << "ID:";
cin >> id;
cout << "Sex(M/F):";
cin >> sex;
cout << "Chinese:";
cin >> cht;
cout << "English:";
cin >> eng;
cout << "Math:";
cin >> math;
// 建立個人資料 
st.setstudent(name,id,sex,cht,eng,math);
// 輸出至檔案 
ofstream outfile ;
outfile.open("student.txt");
outfile << "Name: " << st.Name() << endl
<< "ID: " << st.Id() << endl
<< "Sex: " << st.Sex() << endl
<< "Chinese: " << st.getChinese() << endl
<< "English: " << st.getEnglish() << endl
<< "Math: " << st.getMath() << endl
;    
system("pause");
return EXIT_SUCCESS;
}

2008年5月10日 星期六

在windows下使用bat和wget抓東西

查了一下語法,發現bat也可以這樣用。但到底為什麼要這樣寫,我還是沒有很懂 @@

程式目的:抓下特定網頁,並且用日期去命名
程式碼:
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do wget http://tw.futures.finance.yahoo.com/future/l/opt_TXO_1.html -O%%d-%%e-%%f.html --wait=10


參考網站: