C++的程式..這樣應該不對 但是該如何改呢?

看板Programming作者時間17年前 (2008/08/11 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
我知道這個程式觀念上有問題 雖然可以執行...但這完全不符合物件導向的精神 請問..可否給我一個方向 該如何改呢? 附上我的語法如下: #include <iostream> using namespace std; class fraction { private: int numerator; int denominator; int i,j,end; public: void set_value() { cout<<"輸入起始值:"; cin>>numerator; cout<<"輸入結束值:"; cin>>denominator; print_value(); } void print_value() { if (denominator<numerator) { cout<<"結束值小於起始值,請重新輸入!"<<endl; set_value(); } else { j=0; for (i=numerator ; i<=denominator;) { j+=i; i++; } cout<<"從"<<numerator<<"累加至"<<denominator; cout<<"的總合為:"<<j<<endl; cout<<"請輸入0來結束程式或輸入1來進行下筆計算:"; cin>>end; do_again(); } } void do_again() { if (end == 0) cout<<"感謝您使用本程式!"<<endl; else if (end == 1) set_value(); else { cout<<"您所輸入的數字是錯誤的,請重新輸入:"; cin>>end; do_again(); } } }; int main() { fraction x; x.set_value(); //有多少數量 應該是在程式流程裡面規劃 //x.print_value(); //x.do_again(); return 0; } -- ┌─────KKCITY─────┐ KK免/費/撥/接 bbs.kkcity.com.tw 電話(1):4491999 電話(2):4058-6000 └──From:218.169.124.207 ──┘帳號:kkcity 密碼:kkcity --
文章代碼(AID): #18dopV00 (Programming)
文章代碼(AID): #18dopV00 (Programming)