I need some help with the following assignment. I think I'm pretty close, but I'm missing something. Any help is very much appreciated.

Assignment:
Part 1 : "Create a function template called average(). It will accept two arguments of the same type and computes the arithmetic average. The average is returned as a double.

Overload the average() function to work correctly with three arguments."

Part 2: "Create a class called CollegeCourse with fields for the course ID (for example, "INF 114''), your grade (for example, 'A'), and the credits earned for the CollegeCourse (for example, 2). The CollegeCourse constructor accepts values for these fields as arguments, and calculates a fourth field named honorPoints."

Part 3: "Calculate honorPoints as the product of the grade points (4 for an A, 3 for a B, 2 for a C, and 1 for a D) and the credits.

Overload the +operator() so that honor points for courses can be summed to create a summary CollegeCourse object. Overload the /operator() so that a CollegeCourse object's honorPoints can be divided by an integer. Overload the <<operator() to display the details of a CollegeCourse."

Part 4: "Write a main() program that declares several integers, doubles, and CollegeCourses. Instantiate your CollegeCourses by creating an array of objects. Demonstrate that both versions of average() work correctly with different arguments"

#include <iostream>
#include "CollegeCourse.h"
using namespace std;

template <typename T>
T average(T a, T b, T c)
{
 return (a + b + c) / 2;
}

int main()
{
 
 cout << average(1, 2, 3) << '\n';
 return 0;
}




#include <string>

using namespace std;

class CollegeCourse {
public:
 CollegeCourse(const std::string& id, int cred, char score);
 friend std::ostream& operator<<(std::ostream& out, const CollegeCourse& course);
private:
 std::string courseID;
 int honorPoints;
 int credits;
 char grade;
};

CollegeCourse::CollegeCourse(const std::string& id, int cred, char score)
{
 courseID = id;
 credits = cred;
 grade = score;

{
 int points;

 switch (grade) {
 case 'A': points = 4;
 case 'B': points = 3;
 case 'C': points = 2;
 case 'D': points = 1;
 }

 honorPoints = points * credits;
}

std::ostream& operator<<(std::ostream& out, const CollegeCourse& course);
{
   
  return out << course.courseID << ": " << course.credits
   << " -- " << course.grade << " -- " << course.honorPoints;
   //return 0;
}

CollegeCourse operator+(const CollegeCourse &sum);
    {
        int hnrPoints;
        CollegeCourse hnrPoints;
        hnrPoints.sumCourse = honorPoints++;
        return hnrPoints;
    }

CollegeCourse operator/(const CollegeCourse &number);
    {
       int hnrPoints;
       CollegeCourse hnrPoints;
        hnrPoints.sumCourse = honorPoints/number;
        return hnrPoints;
    }

First: Please ask (a) specific question(s).

Second: Where's the version of average with two arguments instead of three?

Third: at least the two argument version of average() is supposed to return a double, not a T.

Fourth: To me the instructions for the three argument version of average() are vague. In particular can you use two type T variables and a reference to a double as arguments with a return type of void to provide a direct equivalent to the two argument version of average() OR are you to use three type T variables and still return type double (passing three ints and returning an int would not be the equivalent of the two argument version)?

>>return (a + b + c) / 2;

should divide by 3, not 2.

I see no ambiguity in the average template -- all parameters are of type T and the caller cannot pass the first as int, the second as float and the third as double. All three must be of the same type or the compiler will shout at you very loudly :)

and change the function as shown below

void CRecordingUIDlg::OnOnShowRecording()
{
	CShowRecordingsDlg dlg(m_aRec);
	dlg.DoModal();

	MessageBox(NULL, m_aRec[0].m_sArtist);
	// TODO: Add your control notification handler code here
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.