**I have to created my scruct and function but i have to do this in my .cpp file HELP?
    1. Open the file
    2. Set up an empty CDS struct
    3. Start going through the file until EOF (Loop 1)
    4. Read in CD Artist, title, year, rating and numSongs
    5. Check for resize, resize if necessary
    6. createCD using Artist, title, year, rating and numSongs
    7. Using number of songs, start (Loop 2)
    8. Read song title and length
    9. Add song to current CD
    11. end loop 2
    13. Increment current CD
    14. End loop 1
    15. Return CDS**

    *    CDS* createCDS (string filename)
        ifstream inFile;
        int numCDS;

        inFile.open (filename.c_str("cds.txt"));

        CDS** myCDS = new CDS* [numCDS];

        while (!inFile.eof())
            inFIle >> data;
            int artist;
            int title;
            int songs;

            cd->cdArtist = artist;
            cd->cdTitle = title;


Recommended Answers

All 3 Replies

CDS* createCDS (string filename)
    ifstream inFile;
    int numCDS;
    inFile.open (filename.c_str("cds.txt"));  // What does this line do?
    CDS** myCDS = new CDS* [numCDS]; // numCDS is uninitialized
    while (!inFile.eof())
        inFIle >> data; // Capitalization counts.  This won't compile.  What type is data?
        int artist; // integer?
        int title;  // integer?
        int songs;

        // Where is cd declared?
        cd->cdArtist = artist; // artist is uninitialized.
        cd->cdTitle = title;   // title is uninitialized

    // Are you returning anything from this function?

See my added comments.

You have been given a VERY specific structure to follow for this function. When you are at the level that you are, you should need no help with lines like this. Look up the c_str function in the string library. Does it match your function?

inFile.open (filename.c_str("cds.txt"));

Step 6:

createCD using Artist, title, year, rating and numSongs

Is this a helper function that you are supposed to call?

Start over. Read through the steps several times. Add code one step at a time using the steps given. Don't continue until the program compiles without warnings or errors. Then add another step. Right now you are just adding code without thinking it through. You need to program in a systematic, organized way.

I have .cpp and .h files for song, cd and cds. and i have all the files done except for my cds.cpp. thats where the code I made and the list to follow comes in but im just having trouble figuring out where to go from there becuase i opened the file then i created a new struct for CDS. Now the numCDS is for the number of CDS i will have to make. and my while loop is suppose to go through the file until the end and my int artist and int title are suppose to be read in so that i can creat one cd.

You're missing my point. It's fine that you have all of that done. It's GOOD that you have all of that done. But it's irrelevant to what you are posting HERE on Daniweb. We only know what you post and what you posted makes no sense either code-wise (too many bugs) or in terms of following the instructions you posted, which are pretty clear and don't really match your code in my opinion.

Since we don't know what's in song.h or song.cpp or song.h or cd.h or cd.cpp or cds.h or cds.cpp or the makefile, it's hard to give advice except the advice I gave (i.e. pointing out the bugs in your code). We know what you post and no more. Now I can make an educated guess at what is SUPPOSED to be in the files that you listed, but it would only be a guess and if I made an incorrect guess, it would just cause further problems. I can try to deduce your C++ skill level from the code you posted, but again, that's a guess. Remember, WE ARE NOT FAMILIAR WITH THE CLASS YOU ARE TAKING.

Sorry for the all caps, just trying to emphasize. My advice would be to close this thread (i.e. mark it "solved" even though it isn't) and create a new thread explaining exactly where you are stuck and posting the relevant .h files plus the main function. There's not enough information to guide you and the code you posted is too buggy to fix.

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.