Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You\'re a developer for a startup called HowU Study that matches study buddies f

ID: 3575994 • Letter: Y

Question

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 below. You can include constructor(s) if you want.

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

Make sure to print a table showing all the users and their potential matches for studying in one column

In C++ full program with no errors when compiled please.

Explanation / Answer

#include<iostream>
#include<sstream>
#include<string>
#include<list>
#include<fstream>
using namespace std;
#include<stdlib.h>

class User
{
string name;
int classification;
int major;
list<string> expertise;

public:

void setName(string &n){name.assign(n);}
void setClassification(int c){classification=c;}
void setMajor(int m){major=m;}
void setExpertise(string &n){expertise.push_back(n);}

string & getName(){ return name;}
int getClassification(){return classification;}
int getMajor(){return major;}
list<string>::iterator getExpertise(){return expertise.begin();}

void printInfo(){
   cout<<getName()<<endl;
   cout<<getClassification()<<endl;
   cout<<getMajor()<<endl;
   list<string>::iterator iter=getExpertise();
   while(iter!=expertise.end()){
   cout<<*iter<<",";
   iter++;
   }

   cout<<endl;
}
};

class StudyBuddies
{
list<User> ll;

public:

   void printUsers(){

   for(list<User>::iterator itr=ll.begin();itr!=ll.end();itr++)
       itr->printInfo();
   }

   void addUser(User &u){ ll.push_back(u);}

   void readFile(string & fn){
   ifstream ifs;
   char buf[256];
   string tok;
   int c,m;
   list<string> myList;

   ifs.open(fn.c_str(),ifstream::in);

   while(ifs.good()){
       User u;
       ifs.getline(buf,256,' ');

       stringstream ss(buf);
      
       getline(ss,tok,',');
       u.setName(tok);

       getline(ss,tok,',');
       u.setClassification(atoi(tok.c_str()));

       getline(ss,tok,',');
       u.setMajor(atoi(tok.c_str()));  

       while(getline(ss,tok)){
           u.setExpertise(tok);
       }

       addUser(u);
      
   }
   }

void matchStudyBuddies(){
   for(list<User>::iterator itr=ll.begin();itr!=ll.end();itr++)
   {
       for(list<User>::iterator iter2=ll.begin();iter2!=ll.end();iter2++)
       {
           if(itr==iter2) continue;
           if((itr->getName()==iter2->getName()) && (itr->getClassification()==iter2->getClassification()) && (itr->getMajor()==iter2->getMajor())){
               cout<<"Objects having "<<itr->getName()<<" are equal"<<endl;
           }
      
       }
   }
}
};

int main(void)
{

string fN("userData.txt");
StudyBuddies sb;
sb.readFile(fN);
sb.printUsers();
sb.matchStudyBuddies();

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote