Hi so I'm working on inputting a text file then outputting a another file that has a random number 1-100
here is how my input file would look like:
Student1 B-tree
Student10 Homework
Student10 Sorting
Student12 Homework
Student20 Homework
Student4 Quiz
Student4 Sorting
Student7 Quiz
Student1 Homework
Student11 Quiz
Student12 Sorting
Student14 Quiz
Student17 Binary
Student17 Quiz
Code:
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
|
void search(string category, string type){
ifstream in( "dailylog.txt" );
ofstream output("search.txt");
vector<PR> v;
int day;
day = rand()%100+1;
srand(time(0));
if(category == "name"||category=="Name"){
for ( string name, words; in >> name >> words; ) v.push_back( { name, words } );
//std::sort( v.begin(),v.end() , []( PR a, PR b ) { return a.first < b.first; } );
for( PR pr : v )
//if(category == "studentName"){
if(pr.first == type){
srand(time(0));
output<<pr.first<<" "<<pr.second<<" Day visited: "<<day<<endl;
}
}
else if(category == "topic"||category=="Topic"){
for ( string name, words; in >> name >> words; ) v.push_back( { name, words } );
// std::sort( v.begin(),v.end() , []( PR a, PR b ) { return a.second > b.second; } );
for( PR pr : v )
if(pr.second == type){
srand(time(0));
output<<pr.first<<" "<<pr.second<<" Day visited: "<<day<<endl;
}
}
}
| |
Here is my output file example:
Student4 Quiz Day visited: 24
Student7 Quiz Day visited: 24
Student11 Quiz Day visited: 24
Student14 Quiz Day visited: 24
Student17 Quiz Day visited: 24
Student6 Quiz Day visited: 24
Student16 Quiz Day visited: 24
Student8 Quiz Day visited: 24
Student8 Quiz Day visited: 24
Student12 Quiz Day visited: 24
Student5 Quiz Day visited: 24
Student6 Quiz Day visited: 24
How can i Make it random cause not every number should be 24 i just want it to be random from 1-100?
This code is also a search function so it prints everything based on what the user would want so an example of how to call it: srt.search("topic","Quiz");
it would print out every student who would ask about a quiz. And I'm trying to add a number that shows the day they visited.