new programmer needs some help

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;
}
 
J

John Harrison

Patrick Parks said:
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???

Don't mix non-standard I/O functions like getche() with standard C++ I/O,
that is guaranteed to drive you bonkers. In fact don't use non-standard I/O
at all.

Apart from that I don't see any real problems, what exactly is going wrong?
Even if you've made some attempts and they didn't work its a good idea to
post that code because

1) It show more clearly what you are trying to do than any description can.
2) It demonstrates what your level of skill is, and where there are gaps in
your knowledge
3) It proves you been trying for yourself (people don't like to do others
homework when they haven't made any effort).

It would also help to post a sample of the file you are trying to read.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top