[prog] Re: C++
wolf
wolf at wolfrising.net
Sun Mar 14 00:45:19 EST 2004
hello again : ) I stayed up all last night trying to figure this out
and I think my general frustration
with myself for being too dense to understand programming and the flu
finally won out.
thank you for taking the time to respond : ) one of my questions is in
regard to the errors below listing artist, title, yr, and genre as
being undeclared, shouldn't they be recognized since
they're part of the class?
I don't have a text book, I'm not a student, I have a used copy of a
book called programming
c++ 101
this is the current version I'm trying to get working:
#include <iostream>
using namespace std;
class cd {
private:
char artist[30];
char title[50];
int yr;
char genre[10];
public:
cd(); // construct a new blank CD.
void getdata(void);
//void showdata(void); // probably show data and put data are
the same thing
// I sugest that you get rid of this.
void putdata(void);
};
//***********************
class cdlib {
int main()
{
cd rack[10]; // some place to keep 10 CDs
for(int i=0; i<10; i++)
{
rack[i] = new cd(); // create a new CD
rack[i].getdata(); // fill it with data
rack[i].putdata(); // print out the data to confirm its
right.
} // for
for(int i=0; i<10; i++)
{
rack[i].putdata(); // print out the data to confirm its right.
} // for
return 0;
} // main
};
//********
void getdata()
{
/* get the data from the user and write it down to a text file. use
cin */
cout << "Enter the Artist's Name: "<< endl;
cin.getline >> artist;
cout << "Enter the Compact Disk Title: " << endl;
cin.getline >> title;
cout << "Enter the Year the CD was recorded: "<< endl;
cin >> yr;
cout << "Enter the genre for this CD: " << endl;
cin.getline >> genre;
}
void putdata()
{
cout << artist << endl;
cout << title << endl;
cout << yr << endl;
cout << genre << endl;
}
these are the errors that print out when I try to compile the program
from a terminal session:
Compiling...
cd.cpp:22: warning: all member functions in class `cdlib' are private
cd.cpp: In member function `int cdlib::main()':
cd.cpp:29: error: no match for `cd& = cd*&' operator
cd.cpp:4: error: candidates are: cd& cd::operator=(const cd&)
cd.cpp: In function `void getdata()':
cd.cpp:47: error: `artist' undeclared (first use this function)
cd.cpp:47: error: (Each undeclared identifier is reported only once for
each function it appears in.)
cd.cpp:49: error: `title' undeclared (first use this function)
cd.cpp:51: error: `yr' undeclared (first use this function)
cd.cpp:53: error: `genre' undeclared (first use this function)
On Mar 13, 2004, at 11:38 PM, Sue Stones wrote:
> On Sun, 14 Mar 2004 12:43 am, wolf wrote:
>> would anyone happen to be able to figure out how to complete/fix this
>> and get it to work? : )
>> I've been up most of the night and I just can't seem to get a grasp of
>> how. or do I have
>> everything so out of order and messed up it's beyond hope? thanks : )
>
> What is the output when you try and compile it? If you send that to
> the list
> we can say what you need to look at, ie help you understand what it
> means.
>
> Did you check the syntax against your text book, what are you using by
> the
> way? I mentioned that it was likely to be wrong. In particular you
> should
> check the way of accessing methods of objects, it is likely to be "->"
> rather
> than "."
>
> What things have you tried to do. Whilst I am happy to help I
> certainly don't
> have time to do it for you. And you certainly won't learn anything
> that way,
> and learning programming is as the process more than the outcome, so I
> need
> you to explain what you have tried then I can explain what you are
> doing
> wrong, orwhat you haven't thought of etc.
>
> sue
>
>> #include <iostream>
>> using namespace std;
>>
>> class cd {
>> private:
>> char artist[30];
>> char title[50];
>> int yr;
>> char genre[10];
>>
>> public:
>> cd(); // construct a new blank CD.
>> void getdata(void);
>> //void showdata(void); // probably show data and put data are
>> the same thing
>> // I sugest that you get rid of this.
>> void putdata(void);
>> };
>>
>>
>> //***********************
>>
>> class cdlib {
>> int main()
>> {
>> cd rack[10]; // some place to keep 10 CDs
>>
>> for(int i=0; i<10; i++)
>> {
>> rack[i] = new cd(); // create a new CD
>> rack[i].getdata(); // fill it with data
>> rack[i].putdata(); // print out the data to confirm its
>> right.
>> } // for
>> for(int i=0; i<10; i++)
>> {
>> rack[i].putdata(); // print out the data to confirm its
>> right.
>> } // for
>> return 0;
>> } // main
>>
>> };
>> //********
>>
>> void getdata()
>> {
>> /* get the data from the user and write it down to a text file. use
>> cin */
>> cout << "Enter the Artist's Name: "<< endl;
>> cin.getline >> artist;
>> cout << "Enter the Compact Disk Title: " << endl;
>> cin.getline >> title;
>> cout << "Enter the Year the CD was recorded: "<< endl;
>> cin >> yr;
>> cout << "Enter the genre for this CD: " << endl;
>> cin.getline >> genre;
>> }
>>
>> void putdata()
>> {
>> cout << artist << endl;
>> cout << title << endl;
>> cout << yr << endl;
>> cout << genre << endl;
>> }
>>
>>> On Mar 13, 2004, at 1:28 AM, Warren Prasad wrote:
>>>> No void means that they return nothing ... not even NULL
>>>> so the void returning func ends like
>>>>
>>>> getdata()
>>>> {
>>>> // body
>>>> return ;
>>>> }
>>>> For showdata you can use the global pointer fp to access the file
>>>> which u opened in the main function.
>>>>
>>>> use fread to read data from the file .... and run a loop for it with
>>>> the exit co! ndition being the EOF...
>>>>
>>>> If u want i can write the whole program for u..
>>>>
>>>>
>>>> regards,
>>>>
>>>>
>>>> wolf wrote:
>>>> Hello : )
>>>> Thank you for helping : )
>>>> Since getdata() and putdata() are of type void would the correct
>>>> response
>>>> between the braces be:
>>>>
>>>> getdata()
>>>> {
>>>> return getdata;
>>>> }
>>>>
>>>> I'm afraid I don't understand this bit at all:
>>>>> showdata()
>>>>> {
>>>>> // use loop with EOF
>>>>> // to extract data and display it
>>>>> }
>>>>
>>>> how to extract something from type void?
>>>> again thank you for helping : )
>>>>
>>>> On Mar 13, 2004, at 12:40 AM, Warren Prasad wrote:
>>>>> #include
>>>>> //not needed
>>>>> //using namespace std;
>>>>> FILE *fp;
>>>>> class cdlib
>>>>> {
>>>>> char artist[30];
>>>>> char title[50];
>>>>> int yr;
>>>>> char genre[10];
>>>>> public:
>>>>> void getdata();
>>>>> void showdata();
>>>>> void putdata();
>>>>> };
>>>>> int main()
>>>>> {
>>>>> char ch;
>>>>> fp = fopen("library.txt", "+rw");
>>>>> ch = 'y';
>>>>> while(ch == 'y')
>>>>> {
>>>>> getdata();
>>>>> cout << "do you want to enter more data (y/n) : ";
>>>>> cin >> ch;
>>>>> }
>>>>>
>>>>> cout << "do you want to view the data (y/n) : ";
>>>>> cin >> ch;
>>>>> if (ch == 'y')
>>>>> {
>>>>> showdata();
>>>>> }
>>>>> return 0;
>>>>> }
>>>>> void getdata()
>>>>> {
>>>>> // Input each data
>>>>> // donot use loop
>>>>> putdata()
>>>>> // use this to write the data into a file
>>>>> }
>>>>> showdata()
>>>>> {
>>>>> // use loop with EOF
>>>>> // to extract data and display it
>>>>> }
>>>>>
>>>>> !
>>>>>
>>>>>
>>>>>
>>>>> wolf wrote:
>>>>> Hi : )
>>>>>
>>>>> Pretty much the whole thing, I think I bit off more than I can chew
>>>>>
>>>> : )
>>>>>
>>>>> Last time I posted my
>>>>> question someone was nice enough to start the class for me, and
>>>
>>> I've
>>>
>>>>> been trying for
>>>>> about a week to figure out/follow along how classes work but this
>>>
>>> is
>>>
>>>> a
>>>>
>>>>> pretty big jump
>>>>> from what I've tried before. Any advice, ideas, help is very much
>>>
>>> ! > > appreciated : ) I
>>>
>>>>> had finally figured out functions but this seems to be a whole new
>>>>
>>>> game
>>>>
>>>>> : )
>>>>>
>>>>> Thank you!
>>>>>
>>>>> On Mar 12, 2004, at 10:07 PM, Sue Stones wrote:
>>>>>> On Sat, 13 Mar 2004 01:24 pm, wolf wrote:
>>>>>>> Could anyone help me along with getting this to work? Here's the
>>>>>>> original question I'm trying
>>>>>>
>>>>>> G'day Wolf,
>>>>>> Can you be specific about what you are stuck on at the moment?!
>>>>>> sue
>>>>>>
>>>>>>> to figure out:
>>>>>>>> w! rite a simple program to track an individual's cd library,
>>>
>>> the
>>>
>>>>>>>> program should permit the user to enter 10 cds. Each cd
>>>>>>>> should contain the following items: artist, album title, year
>>>
>>> and
>>>
>>>>>>>> genre. the program s! hould display all the cds in order
>>>>>>>> by artist. design a class and represent each album as an object
>>>>
>>>> of
>>>>
>>>>>>>> that class. provide the capability to store the data
>>>>>>>> in a text file and retrieve it again the next time the program
>>>
>>> is
>>>
>>>>>>>> run.
>>>>>>>
>>>>>>> #include
>>>>>>> using namespace std;
>>>>>>>
>>>>>>> class cdlib
>>>>>>>
>>>>>>> {
>>>>>>>
>>>>>>> char artist[30];
>>>>>>>
>>>>>>> char title[50];
>>>>>>>
>>>>>>> int yr;
>>>>>>>
>>>>>>> char genre[10];
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> public:
>>>>>>>
>>>>>>> void getdata();
>>>>>>>
>>>>>>> void showdata();
>>>>
>>>> ! > >>
>>>>
>>>>>> &g! t; void putdata();
>>>>>>
>>>>>>> };
>>>>>>>
>>>>>>> int main()
>>>>>>> {
>>>>>>>
>>>>>>> int cd;
>>>>>>>
>>>>>>> /* get the data from the user and write it down to a text file.
>>>>
>>>> use
>>>>
>>>>>>> cin */
>>>>>>> while (cd < 10)
>>>>>>> {
>>>>>>> cout << "Enter the Artist's Name: "<< endl;
>>>>>>> cin >> artist;
>>>>>>> cout << "Enter the Compact Disk Title: " << endl;
>>>>>>> cin >> title;
>>>>>>> cout << "Enter the Year the CD was recorded: "<< endl;
>>>>>>> cin >> yr;
>>>>>>> cout << "Enter the ge! nre for this CD: " << endl;
>>>>>>> cin >> genre;
>>>>>>> }
>>>>>>>
>>>>>>> return 0;
>>>>>>> }
>>>>>>> /* to put data into the file fopen, fwrite */
>>>>>>>
>>>>>>> putdata()
>>>>>>>
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> getdata()
>>>>>>>
>>>>>>> {
>>>>>
>>>>> &g! t;> /* Read the data from the file fopen. fread */
>>>>>
>>>>>>> return data;
>>>>>>> }
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Programming mailing list
>>>>>>> Programming at linuxchix.org
>>>>>>> http://mailman.linuxchix.org/mailman/listinfo/programming
>>>>>>
>>>>>> _______________________________________________
>>>>>> Programming mailing list
>>>>>> Programming at linuxchix.org
>>>>>> http://mailman.linuxchix.org/mailman/listinfo/programming
>>>>>
>>>>> _______________________________________________
>>>>> Programming mailing list
>>>>> Programming at linuxchix.org
>>>>> http://mailman.linuxchix.org/mailman/listinfo/programming
>>>>>
>>>>> Do you Yahoo!?
>>>>> Yahoo! Mail - More reliable, more storage, less spam
>>>>
>>>> Warren Bhusan Prasad.
>>>> (Software Enggineer)
>>>> Implementation and Support Team,
>>>> Jatayu Softwares,
>>>> Yehelanka, Bangalore.
>>>>
>>>> Phone (mobile) : +91 984 513 1255
>>>>
>>>> Do you Yahoo!?
>>>> Yahoo! Mail - More reliable, more storage, less spam
>>>
>>> Warren Bhusan Prasad.
>>> (Software Enggineer)
>>> Implementation and Support Team,
>>> Jatayu Softwares,
>>> Yehelanka, Bangalore.
>>>
>>> Phone (mobile) : +91 984 513 1255
>>>
>>> Do you Yahoo!?
>>> Yahoo! Mail - More reliable, more storage, less spam
>>
>> _______________________________________________
>> Programming mailing list
>> Programming at linuxchix.org
>> http://mailman.linuxchix.org/mailman/listinfo/programming
>
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming
>
More information about the Programming
mailing list