[prog] Re: C++
wolf
wolf at wolfrising.net
Sun Mar 14 12:47:41 EST 2004
Okay last attempt from staying up all night, it still doesn't quite
work and I can't figure
out what the error messages mean precisely, so once more if anyone can
see a way to
get this to work I'll be eternally grateful, right now I'm just
somewhere past complete
exhaustion : ) one problem I know is I have no idea how to get this to
write to a file.
anyone? bueller? : )
here are the error messages:
Compiling...
cd.cpp:20: error: return type specification for constructor invalid
cd.cpp:20: error: `cd::cd(std::basic_string<char,
std::char_traits<char>,
std::allocator<char> >, std::basic_string<char,
std::char_traits<char>,
std::allocator<char> >, std::basic_string<char,
std::char_traits<char>,
std::allocator<char> >, int)' and `cd::cd(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int)' cannot be
overloaded
cd.cpp:29: error: `void cd::showCD()' and `void cd::showCD()' cannot be
overloaded
cd.cpp:109: error: parse error at end of input
this is line 20:
20 void cd (string sartist, string stitle, string sgenre, int
iyear) {
21 // create a new cd object
22 artist = sartist;
23 title = stitle;
24 genre = sgenre;
25 year = iyear;
this is line 29:
29 void showCD() {
30 // print a cd object
31 cout << artist << " " << genre << " " << title << " " <<
year << endl;
32 }
here's the current version of the program:
#include <iostream>
using namespace std;
class cd {
public:
string artist;
string title;
int year;
string genre;
private:
cd(string artist, string title, string genre, int year);
void showCD();
void saveCDLibrary();
void printCDLibrary();
void cd (string sartist, string stitle, string sgenre, int iyear) {
// create a new cd object
artist = sartist;
title = stitle;
genre = sgenre;
year = iyear;
};
void showCD() {
// print a cd object
cout << artist << " " << genre << " " << title << " " << year <<
endl;
}
void saveCDLibrary(cd cdLibrary[], int length) {
// need a fileIO stream of some sort.
for (int i; i < length; i++) {
cin << cdLibrary[i].showCD();
}
}
void printCDLibrary(cd cdLibrary[], int length) {
// This maybe needs sorted...
for (int i; i < length; i++) {
cout << cdLibrary[i].showCD();
}
}
void readCDLibrary(cd cdLibrary, int length) {
string input, artist, title, genre;
int year;
// Open the file ?
for (int i = 0; i < length; i++) {
inputstream >> input;
// artist, title, genre, year
cdLibrary[i] = new cd(artist, title, genre, year);
}
}
int main()
{
int CDcount = 0;
const int LIBRARY_SIZE = 10;
string artist, title, genre;
int year;
cd cdLibrary[LIBRARY_SIZE];
// Ask if they want to read the CDs from a file or enter new
// data:
cout << "Read from file (1) or Enter new data (0)? ";
cin >> ans;
if (ans) {
// read from the file?
readCDLibrary(cdLibrary, LIBRARY_SIZE);
} else {
// read in information about CDs
while (cdCount < LIBRARY_SIZE) {
cout << "Enter CD Information:" << endl;
cout << "Enter year: (0 to quit)";
cin >> year;
if (year == 0) { break; }
cout << "Enter artist: ";
cin >> artist;
cout << "Enter title: ";
cin >> title;
cout << "Enter genre: ";
cin >> genre;
cdLibrary[cdCount] = new cd(artist, title, genre, year);
cdCount++;
}
}
saveCDLibrary(cdLibrary, LIBRARY_SIZE);
printCDLibrary(cdLibrary, LIBRARY_SIZE);
return 0;
}
> __________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming
>
More information about the Programming
mailing list