In: Computer Science
Debug please. It's in C++
#include<iostream>
#include<string>
using namespace std;
template <class T>
double half(int x)
{
double h = x / 2;
return h;
}
class TuitionBill
{
friend ostream& operator<<(ostream, TuitionBill);
private:
string student;
double amount;
public:
TuitionBill(string, double);
double operator/(int);
};
TuitionBill::TuitionBill(string student, double amt)
{
student = student;
amount = amt;
}
double TuitionBill::operator/(int factor)
{
double half = amount / factor;
return hafl;
}
ostream& operator<<(ostream& o, TuitionBill)
{
o << t.student << " Tuition: $" << t.amount << endl;
return o;
}
int main()
{
int a = 47;
double b = 39.25;
TuitionBill tb("Smith", 4000.00);
cout << "Half of " << a << " is " << half(a) << endl;
cout << "Half of " << b << " is " << half(b) << endl;
cout << "Half of " << tb << " is " << half(tb) << endl;
return 0;
}
#include<iostream> #include<string> using namespace std; template <class T> double half(T x) { double h = x / 2; return h; } class TuitionBill { friend ostream& operator<<(ostream&, const TuitionBill&); public: double amount; string student; TuitionBill(string, double); double operator/(int); }; TuitionBill::TuitionBill(string student, double amt) { student = student; amount = amt; } double TuitionBill::operator/(int factor) { double half = amount / factor; return half; } ostream& operator<<(ostream& o, const TuitionBill& t) { o << t.student << " Tuition: $" << t.amount; return o; } int main() { int a = 47; double b = 39.25; TuitionBill tb("Smith", 4000.00); cout << "Half of " << a << " is " << half(a) << endl; cout << "Half of " << b << " is " << half(b) << endl; cout << "Half of " << tb << " is " << half(tb) << endl; return 0; }