P
Patrick Parks
hi guys, i am trying to read in CD info from a file and put it into an
array, using a CD class. I have been working here for about 6-8 hours
trying to get the input file into an array. i just need some help
starting it. It needs to read 15 15 rows with 6 columns in each row.
Any help???
thx a bunch.....
#if !defined(microsoft)
#include
#define cls() system ("cls");
#endif
#include
#include
#include
#include
#include
using namespace std;
class CD
{
private:
int numberID1;
char nameArtist[20];
int numSongs;
char genderArtist[10];
float cdPrice;
char artistLabel[25];
char cdArray[15];
public:
CD(); // default constructor
void getData(); //getData
void reportData();
void getkeyedData();
~CD(); //destructor
};
CD::CD()//constructor
{
numberID1 = 0;
nameArtist[0] = '\0';
numSongs = 0;
genderArtist[0] = '\0';
cdPrice = 0;
artistLabel[0] = '\0';
}
CD::~CD()//destructor
{
}
ifstream infile;
ofstream outfile;
ofstream errorlog;
int main ()
{
void instructions();
int menu();
void printCDList(const CD[]);
CD myCD;
CD CDList[50];
int i;
int data_amt;
int response;
outfile.open("cdlist.txt");
errorlog.open("errorlog.txt");
arraytest.open("arraytest.txt");
do
{
char filename[80];
infile.clear();
cout << "Please enter the name of the file with the CD information in
it: ";
cin >> filename;
infile.open(filename, ios::in);
}
while (infile.fail());
instructions();
infile>>data_amt;
for(i=1; i<=data_amt; i++)
{
cout << "CD #" << i <<endl;
myCD.getData();
getche();
CDList=myCD;
}
getche();
response = menu();
switch(response)
{
//case 1: myCD.idSort();
// getche();
// break;
//case 2: myCD.artistSort();
// getche();
// break;
case 3: myCD.getkeyedData();
getche();
break;
//case 4: myCD.changePrice();
// getche();
// break;
case 5: myCD.reportData();
cout << "Printing report......" << endl;
cout << "Please hit enter to finish report" << endl;
getche();
break;
case 6: break;
}
return 0;
}//end of main
/*
}
if(menuAgain[0]=='Y'||menuAgain[0]=='y')
{
getche();
menu();
}
else
cout << "Thank you for using this program. Goodbye!" << endl;
getche();
return 0;
}
//**********************************************************************
// Function Name: instructions
// Purpose: To explain to the user what the program will do
// Parameters:
// Input:
// Input & Output:
// Return Value:
// Non-local Variables Used:
// Functions Called:
//**********************************************************************
*/
void instructions()
{
cout << "This program will allow you to enter the information for a CD
from the keyboard and from a file." << endl;
cout << "It will accept: " << endl;
cout << "The UPC code on the CD, the Artist's name, the gender of the
artist, the number of songs on the CD, the price of the CD, and the
label that released the CD" << endl;
}
int menu()
{
int ans;
do
{
cls();
cout<<"Choose from one of the following options:"<<endl;
cout<<"1. Sort and display the list of CD's by ID number"<<endl;
cout<<"2. Sort and display the list of CD's by Artists name"<< endl;
cout<<"3. Enter a new CD from the keyboard"<<endl;
cout<<"4. Change the price of one of the CD's"<<endl;
cout<<"5. Create a report of the CD's sorted by ID number"<<endl;
cout<<"6. Exit this program"<<endl;
cin>> ans;
}
while((ans<1)||(ans>6));
return ans;
}
array, using a CD class. I have been working here for about 6-8 hours
trying to get the input file into an array. i just need some help
starting it. It needs to read 15 15 rows with 6 columns in each row.
Any help???
thx a bunch.....
#if !defined(microsoft)
#include
#define cls() system ("cls");
#endif
#include
#include
#include
#include
#include
using namespace std;
class CD
{
private:
int numberID1;
char nameArtist[20];
int numSongs;
char genderArtist[10];
float cdPrice;
char artistLabel[25];
char cdArray[15];
public:
CD(); // default constructor
void getData(); //getData
void reportData();
void getkeyedData();
~CD(); //destructor
};
CD::CD()//constructor
{
numberID1 = 0;
nameArtist[0] = '\0';
numSongs = 0;
genderArtist[0] = '\0';
cdPrice = 0;
artistLabel[0] = '\0';
}
CD::~CD()//destructor
{
}
ifstream infile;
ofstream outfile;
ofstream errorlog;
int main ()
{
void instructions();
int menu();
void printCDList(const CD[]);
CD myCD;
CD CDList[50];
int i;
int data_amt;
int response;
outfile.open("cdlist.txt");
errorlog.open("errorlog.txt");
arraytest.open("arraytest.txt");
do
{
char filename[80];
infile.clear();
cout << "Please enter the name of the file with the CD information in
it: ";
cin >> filename;
infile.open(filename, ios::in);
}
while (infile.fail());
instructions();
infile>>data_amt;
for(i=1; i<=data_amt; i++)
{
cout << "CD #" << i <<endl;
myCD.getData();
getche();
CDList=myCD;
}
getche();
response = menu();
switch(response)
{
//case 1: myCD.idSort();
// getche();
// break;
//case 2: myCD.artistSort();
// getche();
// break;
case 3: myCD.getkeyedData();
getche();
break;
//case 4: myCD.changePrice();
// getche();
// break;
case 5: myCD.reportData();
cout << "Printing report......" << endl;
cout << "Please hit enter to finish report" << endl;
getche();
break;
case 6: break;
}
return 0;
}//end of main
/*
}
if(menuAgain[0]=='Y'||menuAgain[0]=='y')
{
getche();
menu();
}
else
cout << "Thank you for using this program. Goodbye!" << endl;
getche();
return 0;
}
//**********************************************************************
// Function Name: instructions
// Purpose: To explain to the user what the program will do
// Parameters:
// Input:
// Input & Output:
// Return Value:
// Non-local Variables Used:
// Functions Called:
//**********************************************************************
*/
void instructions()
{
cout << "This program will allow you to enter the information for a CD
from the keyboard and from a file." << endl;
cout << "It will accept: " << endl;
cout << "The UPC code on the CD, the Artist's name, the gender of the
artist, the number of songs on the CD, the price of the CD, and the
label that released the CD" << endl;
}
int menu()
{
int ans;
do
{
cls();
cout<<"Choose from one of the following options:"<<endl;
cout<<"1. Sort and display the list of CD's by ID number"<<endl;
cout<<"2. Sort and display the list of CD's by Artists name"<< endl;
cout<<"3. Enter a new CD from the keyboard"<<endl;
cout<<"4. Change the price of one of the CD's"<<endl;
cout<<"5. Create a report of the CD's sorted by ID number"<<endl;
cout<<"6. Exit this program"<<endl;
cin>> ans;
}
while((ans<1)||(ans>6));
return ans;
}