C Youre a developer for a startup called HowU Study that mat
C++!! You\'re a developer for a startup called HowU Study that matches study buddies for classes depending on the experience of each user. In this lab you must:
create a class called User that contains the following:
name
classification
major
expert class list (what classes the user feels they are an expert in)
mutators and accessors for each private variable
printUsers function that prints all the users of the system
matchStudyBuddy function that matches users based on classes they have in common. (Meaning two or more classes that match)
read a set of users from a file userData.txt
read in a whole line from the file
parse the line, you will have to change the delimiter of the getline statement to be comma delimited
Use this as an example
Solution
Code:
#include<iostream>
#include<string>
#include<list>
#include <fstream>
#include<sstream>
using namespace std;
int count=0;
class User
{
private:
string name;
string classification;
string major;
list<int> classes;
public:
User()
{
name=\"\";
classification=\"\";
major=\"\";
}
void setname(string n)
{
name=n;
}
string getname()
{
return name;
}
void setclassification( string c)
{
classification=c;
}
string getclassification()
{
return classification;
}
void setmajor(string m)
{
major=m;
}
string getmajor()
{
return major;
}
void setclasses(int c)
{
classes.push_back(c);
}
list<int> getclasses()
{
return classes;
}
};
User u[100];
void print()
{
for(int i=0;i<count;i++)
{
cout<<u[i].getname()<<endl;
}
}
void matchstuddybuddy()
{
list<int> a;
list<int> b;
int match[10];
int cou=0;
int m=0;
for(int i=0;i<count;i++)
{
m=0;
a=u[i].getclasses();
for(int k=0;k<count;k++)
{
cou=0;
b=u[k].getclasses();
for(list<int>::iterator it1 = a.begin(); it1 != a.end(); it1++)
{
for(list<int>::iterator it2 = b.begin(); it2 != b.end(); it2++)
{
if(*it1==*it2)
{
cou++;
}
}
}
if(cou>2)
{
match[m]=k;
m++;
}
}
cout<<\"Matching of \"<<u[i].getname()<<endl;
for(int l=0;l<m;l++)
{
cout<<u[l].getname()<<endl;
}
}
}
int main()
{
ifstream in;
in.open(\"inp.txt\");
string line;
while(getline(in,line,\',\'))
{
istringstream ss(line);
string name;
ss>>name;
u[count].setname(name);
string classif;
ss>>classif;
u[count].setclassification(classif);
string major;
ss>>major;
u[count].setmajor(major);
int val;
while(ss>>val)
{
u[count].setclasses(val);
}
count++;
}
matchstuddybuddy();
system(\"pause\");
return 0;
}
input:
xxx yyy zzz 1 2 3, yyy kkk mmm 1 2
Output:


