各位C++大神們,小妹真的是走投無路只好來這裡發問了,因為我問教授教授沒時間理我、上美國C++論壇問得不到答案、我沒一個朋友會C++,所以只好來這裡以點數方式希望能得到個解答...
以下是我自己寫得非常簡單的計算平均數的程式,請問如何把這個程式重寫成OOP型態?
不好意思內容都是英文,因為我是在美國上的課,只是真的快被搞瘋了,我完全不知道要從何開始,所以希望有人能把我這個程式重寫成OOP讓我參考,因為我後續還有一堆程式沒貼上來,之所以來發問只是想有個範例讓我參考。
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector < float > num;
float sum = 0;
float average = 0;
int totalCount = 0; // total number count
// Loop for read in total number count
cout << "Please enter total number count\n";
cin >> totalCount;
sum = 0;
// Loop for read in numbers
for (int i = 0; i < totalCount; ++i)
{
num.push_back(0);
cout << "\nPlease enter the number\n" << "Number " << i + 1 << ": ";
cin >> num[i];
sum += num[i]; // calculate the sum
}
// Calculate the average
average = sum / totalCount;
cout << "\n\nAverage: " << average << "\n";
return 0;
}
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
留言列表