Join 132,615 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 965 people online right now. Registration is fast and FREE... Join Now!
#include <iostream> #include <string> #include "collegeCourse.h" using namespace std;
template <typename T> T average(T a, T b) { return (a + b) / 2; }
template <typename T> T average(T a, T b, T c) { return (a + b + c) / 3; }
int main() { int a=7, b = 26, c = 100; double d = 39.25, e = 2.01, f = 4.2; double avg; collegeCourse myClass[3]={collegeCourse("ENG 101", 'A', 1), collegeCourse("PSY251", 'B', 3), collegeCourse("HIS301", 'D', 4)};
cout << "The average of " << a << ", " << b << " is: " << average(7, 26) << endl; cout << "The average of " << a << ", " << b << ", " << c << "is: " << average(7, 26, 100) << endl; cout << "The average of " << d << ", " << e << ", " << f << " is: " << average(39.25, 2.01, 4.2) << endl;
#include <iostream> #include <string> #include "collegeCourse.h" using namespace std;
template <typename T> T average(T a, T b) { return (a + b) / 2; }
template <typename T> T average(T a, T b, T c) { return (a + b + c) / 3; }
int main() { int a=7, b = 26, c = 100; double d = 39.25, e = 2.01, f = 4.2; double avg; collegeCourse myClass[3]={collegeCourse("ENG 101", 'A', 1), collegeCourse("PSY251", 'B', 3), collegeCourse("HIS301", 'D', 4)};
cout << "The average of " << a << ", " << b << " is: " << average(7, 26) << endl; cout << "The average of " << a << ", " << b << ", " << c << "is: " << average(7, 26, 100) << endl; cout << "The average of " << d << ", " << e << ", " << f << " is: " << average(39.25, 2.01, 4.2) << endl;
return 0; }
change this: collegeCourse::collegeCourse(string& id, char score, int credits) to this: collegeCourse::collegeCourse(const string& id, int credits, char score)
great thanks. Now i am having the trouble i think with my operators can anyone help me with this.
I need have my output look like this but I can't get it to pull the average from my arrray.
and your output would look like this: The average of 7 and 26 is 16 The average of 39.25 and 2.01 is 20.63
The average of ENG101 Grade: A Credits: 3 Honor points: 12 PSY251 Grade: B Credits: 3 Honor points: 9 is 10.5
The average of 7, 26 and 100 is 44 The average of 39.25, 2.01 and 4.2 is 15.1533
The average of ENG101 Grade: A Credits: 3 Honor points: 12 PSY251 Grade: B Credits: 3 Honor points: 9 HIS301 Grade: D Credits: 4 Honor points: 4 is 8.3333
int main() { int a=7, b = 26, c = 100; double d = 39.25, e = 2.01, f = 4.2; double avg; collegeCourse myClass[3]={collegeCourse("ENG 101", 'A', 1), collegeCourse("PSY251", 'B', 3), collegeCourse("HIS301", 'D', 4)};
cout << "The average of " << a << ", " << b << " is: " << average(7, 26) << endl; cout << "The average of " << a << ", " << b << ", " << c << "is: " << average(7, 26, 100) << endl; cout << "The average of " << d << ", " << e << ", " << f << " is: " << average(39.25, 2.01, 4.2) << endl;
collegeCourse anInstance; cout << "The average of " << myClass[0] << "and " << myClass[1] << endl; cout << " is " << endl;
collegeCourse anInstance; cout << "The average of " << myClass[0] << " , " << myClass[1] << " and " << myClass[2] << endl; cout << " is " << endl;
return 0; }
This post has been edited by snyderchip: 16 Jul, 2008 - 12:34 PM