close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
Dog-Lovers' Tees.

Unleash yourself and shop our special collection of tees and accessories for you and your pooch.
From our sponsors
C++:把簡單程式重寫成OOP【20點】
Apr 19th 2014, 22:40

各位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.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 jmuko90 的頭像
    jmuko90

    2016【韓劇】奶酪陷阱劇情簡介及人物介紹奶酪陷阱 EP03 預告奶酪陷阱 線上看奶酪陷阱(捕鼠器裡的奶酪) 第1集

    jmuko90 發表在 痞客邦 留言(0) 人氣()