Jump to content
Sign in to follow this  
CoolMaster

Classes?

Recommended Posts

ok so i changed the compare records and that worked, now I just gotta get the "default" record working and the readin from file function going, see I dont know what parameters to use and what .open to use with it, because Im assuming the syntax would be normal like infile >> id ...etc...

Share this post


Link to post
Share on other sites

Right. So I'll ask again. Do you see anything wrong with this code?:

void vinylRecord::readRecord2( ifstream &infile )
{
.open("myfile.txt");

}

 

To me, it looks like something is missing from the left side of the period...

Share this post


Link to post
Share on other sites

yeah I know, but I DONt know what goes there, since infile will not work, do i need to make up a new name for it ? im not THAT retarded lol

 

 

edit: Ok weird infile works now.....odd

 

but i get this error instead now

 

lab1.obj : error LNK2019: unresolved external symbol "public: int __thiscall vinylRecord::compareRecords(class vinylRecord,int)" ([email protected]@@[email protected]@Z) referenced in function _main

1>E:\Lab1\Debug\Lab1.exe : fatal error LNK1120: 1 unresolved externals

 

but I believe that has to do with the compare records so, when im reading in the info, do i use cin >> or infile >>?

cause someone said something about using cin when u passed ifstream in a function, but I could just be Bsing?

 

EDIT: yup it's the compare records.

Edited by CoolMaster

Share this post


Link to post
Share on other sites
but i get this error instead now

See, there ya go. You knew you put that in the parameter list for a reason, didn't you? :P

 

when im reading in the info, do i use cin >> or infile >>?

I assume you're talking about the readRecord2 function?

 

Let me ask you this: If you used cin, then what would be the point of declaring the infile object? :)

Share this post


Link to post
Share on other sites

I know but I had heard somewhere...u coudl use cin when u passed it as a parameter, so ill use the normal thing. let me get that done and post the function for that to see if it looks ok

 

btw thanks for the help I got so rushed this weekend with work and tests the lab kinda took the backseat lol

Share this post


Link to post
Share on other sites

alright this should be it

 

void vinylRecord::readRecord2( ifstream &infile )

{

infile.open("myfile.txt");

 

infile >> ID;

infile >> purmonth >> purday >> puryear;

infile >> price;

infile.ignore(500, '\n');

getline (infile,name);

getline (infile,album);

getline (infile,album);

infile >> relmonth >> relyear;

infile.ignore(500, '\n');

getline (infile,name);

getline (infile,album);

infile >> relmonth >> relyear;

infile.ignore(500, '\n');

getline (infile,talk);

infile >> rating;

infile >> saleprice;

 

}

 

no errors so ;-D

 

 

here's his "SAMPLE" text file we will be reading from

 

 

987654321 8 31 2007 2.15

Van Halen

Van Halen

2 1978

Four way split photos of all band members, VH logo centered over photos

3 4.99

 

 

hmmm...... it's not reading it correctly it would seem, should i read "myfile" then c_str

cause i named the file myfile and it's a .txt file, so......should I rename it myfile.txt or whut

 

EDIT: ok nm i hadnt even called the function yet :-P

but it still says readfunction2 blah blah doesnt take 0 parameters.......what parameters should I put in it?

Edited by CoolMaster

Share this post


Link to post
Share on other sites
but it still says readfunction2 blah blah doesnt take 0 parameters.......what parameters should I put in it?

You tell me! :)

 

You just typed out the function protocol for me... it's right here:

void vinylRecord::readRecord2( ifstream &infile )

Looks to me like this call needs to have a "ifstream" object passed into it. That's how you prototyped it, after all.

Share this post


Link to post
Share on other sites

ya but it wont take infile, because it says it's undeclared, and it wont take both......so?

 

and i tried making up one, that doesnt work either, it just says it's undeclared

Share this post


Link to post
Share on other sites
ya but it wont take infile, because it says it's undeclared, and it wont take both......so?

 

and i tried making up one, that doesnt work either, it just says it's undeclared

This is because you're not thinking about what you're doing. :) Stop a second, and think about what you're asking the code to do.

 

If infile is undeclared, how can you fix that? What is infile? Or rather, what's it supposed to be? Why are you passing it into your function in the first place? It's supposed to do something.

 

Your function prototype tells you what type of object it's supposed to be, so you already know that. All you need to do is declare it as that type of object.

Share this post


Link to post
Share on other sites

so i should just in the main be like......ifstream infile?

and then put infile in the parameters?

 

EDIT: sweet it worked.

 

but somethings messed up

 

 

--------------------Printing Data--------------------

ID: 987654321

Purchase Date: 8 31 2007

Purchase Price: 2.15

Band/Artist:

Album: Van Halen

Release Date: 232399236 4274927

Description of the Album Cover:

Condition Rating:

Sale Price: 8.94233e-039

-----------------------------------------------------

 

my ignores or something are off?

 

 

here's the function code btw

 

void vinylRecord::readRecord2( ifstream &infile )
{
infile.open("myfile.txt");

infile >> ID;
infile >> purmonth >> purday >> puryear;
infile >> price;

getline  (infile,name);
getline  (infile,album);
infile >> relmonth >> relyear;
infile.ignore(500, '\n');
getline  (infile,name);
getline  (infile,album);
infile >> relmonth >> relyear;
infile.ignore(500, '\n');
getline  (infile,talk);
infile >> rating;
infile >> saleprice;

}

 

 

should I be using "get" or something?

Edited by CoolMaster

Share this post


Link to post
Share on other sites

It looks like you're not reading the data in in the right order. Your read2 function above looks a little screwy. Lots of repeated lines. Also, you're reading the "album" in twice. You do realize that in the example, he's using a self-titled album, right? As in the artist is Van Halen, and the album is also called Van Halen. So your output should say "Van Halen / Van Halen".

 

Also, make sure to tell your teacher that using a self-titled album for this kind of example is ULTRA lame. That rates him very high on the douchebaggery scale :P

 

Go over your read-in function code again, and make sure you're reading things in the right order. It looks like that's your problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×