-
Example Class?
I'm tring to make a program that takes information for CD sales from a local music store. It takes the infor and then calculates total sales and then displays them. I'm having no luck with it.
Could anybody please help? I mean does anyone have a similar program already made, so I can look over it for correct syntax and maybe some code snips?!?!?
I'm desperate!
NOMAD:eek: :confused:
-
Or in fact I'll post what I have and if some bored soul wants to fix it that would be even better! thanks!
Code:
#include <iostream>
using std :: ostream;
using std :: istream;
using std :: basic_istream;
using std :: basic_ostream;
using std :: cout;
using std :: cin;
#include <iomanip>
using std :: ios;
#include <string>
using namespace std;
enum CDCatagory { Show, Pop, Rock, Classical, Country, Religious, International, Gothic, Other };
//template <class CD>
class CD {
unsigned long int UPC;
string Artist;
string Title;
unsigned short int PlayTime;
CDCatagory Category;
float Price;
unsigned int Sold;
CD* CDprt;
public:
CD();
~CD() {
delete [] CDPtr;
};
CD(unsigned long int id);
CD(CD & c);
bool operator == (const CD c);
bool operator < (const CD c);
CD operator = (const CD c);
friend istream & operator >> (istream & i, CD & c)
{
int iTempCategory;
cout << "Enter UPC: ";
i >> c.UPC;
i.ignore(1);
cout << "Enter Artist: ";
i.getline(c.Artist, 40, "\n");
cout << "Enter Title: ";
i.getline(c.Title, 40, "\n");
cout << "Enter Playing Time: ";
i >> c.PlayTime;
i.ignore(1);
cout << "Show, Pop, Rock, Classical, Country, Religious, International, Gothic Rock, Other";
cout << "Enter Category (1-9): ";
i >> iTempCategory;
switch (iTempCategory) {
case 1: c.Category = Show;
break;
case 2: c.Category = Pop;
break;
case 3: c.Category = Rock;
break;
case 4: c.Category = Classical;
break;
case 5: c.Category = Country;
break;
case 6: c.Category = Religious;
break;
case 7: c.Category = International;
break;
case 8: c.Category = Gothic;
break;
default : c.Category = Other;
break;
};
cout << "Enter Retail Price: ";
i >> float(c.Price);
i.ignore(1);
cout << "Enter Unit Sales: ";
i >> c.Sold;
};
friend ostream & operator << (ostream & o, const CD & c)
{
o << c.UPC << " "
<< c.Title << " "
<< c.Artist << " "
<< c.Category << " "
<< c.PlayTime << " "
<< c.Price << " "
<< c.Sold;
};
};
CD<CD>::CD(int i) {
CD(i).Artist = "NO ARTIST";
CD(i).Title = "NO TITLE";
CD(i).UPC = 0;
CD(i).Price = "0.00";
CD(i).Sold = 0;
CD(i).PlayTime = 0.0;
CD(i).Category = Other;
};
CD<CD>::~CD() {
Artisit = "";
Title = "NO TITLE";
UPC = 0;
Price = "0.00";
Sold = 0;
PlayTime = 0.0;
Category = Other;
};
CVector CVector:: operator+ (CVector param)
CD CD:: operator= (CD c) {
CD c2;
c2.UPC = c.UPC;
c2.Artist = c.Artist;
c2.Title = c.Title;
c2.PlayTime = c.PlayTime;
c2.Category = c.Category;
c2.Sold = c.Sold;
c2.Price = c.Price;
return (c2);
};
bool CD:: operator== (CD c1, CD c2) {
if (c1.UPC == c2.UPC) {
return true;
}
else
return false;
};
bool CD:: operator< (CD c1, CD c2) {
if (c1.UPC < c2.UPC) {
return true;
}
else
return false;
};
template <class CD>
void BubbleSort(itemtype values[], int start, int end) {
for (int index = end, index > start, index--) {
CD temp;
if (values[index] < values[index-1]) {
temp = values[index];
values[index] = values[index-1];
values[index-1] = temp;
};
};
return 0;
};
void PrintHeader() {
cout << " Tower Records Store"
<< " Monthly Report for May 2001"
<< " Prepared by "
<< endl;
cout << " Unit Sold"
<< endl;
cout << "UPC# Title Artist Label Time Price Sold Sales"
<< endl;
return 0;
}
NOMAD
-
Anything would help, if you see an error could you please tell me. I can't find a place that explains this. Not even my textbook given a detailed anough explanation to classes!
NOMAD:mad:
-
I don't have the time to read all that code, just one little thing:
using namespace std;
is the same as a
using std::xxx
declaration for every element of std.
You don't need all those using std::* declarations since you have the using namepsace std andyway.
Maybe I'll take a look later.