Reading info from txt

Pages: 12
Just have one more question. I'll need to create the like and dislike option. Could you please tell me how do I make a counter for that option?

I'm sorry, I don't understand quite what you mean. Do you want to read that information in from the file, or what exactly?
The aim of the project is to develop an application to manage the information of a radio
station. A radio station has a name, a list of music tracks to broadcast and a top ten list of
the music tracks preferred by the listeners and a list of radio listeners (users). Each music
track is characterized by a unique integer id, its title, artist, author, album, music genre,
year, number of "likes", number of "dislikes". A radio listener is someone that has a unique
ID, a name, age, gender and a play list (list of music track ids). The play list of a user must
have information concerning the music track. The top ten list is sorted, in descending order,
by the difference between the number of "likes" and the number of "dislikes" of the music
tracks. Information concerning the radio station and the users is kept updated in files. To
have access to the radio station facilities a user must register himself at the application
(simply fill in the user information mentioned above). The radio station registers the number
of times each track is played in a given period and assigns a prize to the user with the
hightest number of hits in his/her playlist.

Here you go.

Regards
I think the 'like' and 'dislike' seem like two more columns to be added to the file in a similar way to the ID.

However, some of the data items, including the ID are integers, while the program currently treats everything as a string. That isn't a major problem, you can convert a std::string to an integer using for example atoi(id.c_str()) where id is the string containing the ID number. The same would apply to other numeric fields. Year is probably OK as a string but like/dislike are clearly numeric items which can be incremented or decremented at some point and should be treated as integers too.

From the description above I can see there is quite a lot more to this project, this is just one part of it.
Hello again.
Yes, I noticed using strings as intergers might be dangerous and Im willing to change that.

Meanwhile, I created a "program" to create a new user and write it in the proper txt file.

The thing is
How do i turn this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>


    
    using namespace std;
    int main5 () {
    
		string ID;
		string name;
		string age;
		string gender;
		string playlist;
      ofstream myfile;
	  
 
      myfile.open ("User.txt", fstream::in | fstream::out | fstream::app);
	  cout << "ID No. : ";
	  cin >> ID;
	  cout << "User name : ";
	  cin >> name;
	  cout << "Age: ";
	  cin >> age;
	  cout << "Gender : ";
	  cin >> gender;
	  cout << "Playlist : ";
	  cin >> playlist;
	  cout << endl;
	  
	  
	  
	  
      myfile << ID << "," << name << "," << gender << "," << age << "," << gender << "," << playlist<< endl;
	  
      myfile.close();
      return 0;
    }


Into a function?
I'd like to be able to use "AddNewUser" somewhere else.

Any clue?

Regards
If you're not familiar with defining your own functions, you should probably work through some of the simple examples in the tutorial pages:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

Basically, you need to decide whether the function requires any parameters to be supplied in order for it to work, and whether the function will need to return any information to the calling program.

Initially, you might write a fully isolated function which does not pass anything in either direction, but that may not be very useful in the context of a larger program.
Topic archived. No new replies allowed.
Pages: 12