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

write a c++ program that stimulates a questionnaire ... Question: Write a C++ pr

ID: 3576564 • Letter: W

Question

write a c++ program that stimulates a questionnaire ... Question: Write a C++ program that stimulates a questionnair... Bookmark Write a C++ program that stimulates a questionnaire to find a roommate from your computer class. You will ask the user various questions that might determine a suitable match, at least 5 conditions satisfied from the potential questions. Store the names of students who matches your preference in a file called matchfile. Also, store names of students who are not your preferred match in one-dimensional array called NoMatch, size 21.

a. Print the names of students from the matchfile

b. Print the total number of students interviewed

c. Print the names of students from the array NoMatch

Note: potential questions

How often do you clean?

What do you do on the weekends?

Do you like to have friends over or keep the party outside?

Do you smoke?

How often do you drink at home?

Do you have references?

What time do you go to bed?

Do you have any pets?

What is your major hobby?

write a program in C++ language with using loop, functions, condition statements, enum, arrays, struct. // COMMENT IS MANDATORY.

Explanation / Answer

#include<iostream>
#include<cstring>
#include<vector>
#include<cstdlib>
#include<fstream>
using namespace std;
int main(){
   vector<string> noMatch;
   vector<string> matchArr;
   int clean;
   string weekend,fover;
   int smoke,drink;
   int bedTime;
   char reff,pet;
   string hobby,name;
   int totalInterviewed=0;
   int matchCount=0;
   char choice;
   fstream fileName;
//   fileName<<"Names of the student who matched the criteria are stored below...!!!!!"<<endl;
   fileName.open("matchfile.txt", ios::in|ios::out|ios::app);
   do{
       cout<<" Please enter your name:";
   getline(cin,name);
   cout<<" What do you do on the weekends?";
   getline(cin,weekend);
   cout<<" Do you like to have friends over or keep the party outside?";
   getline(cin,fover);
  
   cout<<" What is your major hobby?";
   getline(cin,hobby);  
   cout<<" What time do you go to bed?";
   cin>>bedTime;
   cout<<" How often do you clean?";
   cin>>clean;  
   cout<<" How often do you smoke??";
   cin>>smoke;
   cout<<" How often do you drink at home?";
   cin>>drink;
   cout<<" Do you have references?";
   cin>>reff;
   cout<<" Do you have any pets?";
   cin>>pet;
   cout<<"Press y to continue:";
   cin>>choice;
   if(weekend.compare("party")==0)
       matchCount++;
   else if(fover.compare("friends over")==0)
   matchCount++;
   else if(bedTime==10)
   matchCount++;
   else if(hobby.compare("photography")==0)
   matchCount++;
   else if(clean>3)
   matchCount++;
   else if(smoke<2)
   matchCount++;
else if(drink<2)
   matchCount++;
else if(reff=='y')
   matchCount++;
   else if(pet=='y')
   matchCount++;
  
   if(matchCount>=5){
       fileName<<" "<<name<<endl;
   }      
   else{
       noMatch.push_back(name);  
   }
  
   totalInterviewed++;
   }while(choice=='y'||choice=='Y');

int a = 0;
string line1[30];
if(!fileName)
{
cout<<"Error opening output file"<<endl;
return -1;
}
  
while(!fileName.eof())
{
getline(fileName,line1[a]);
matchArr.push_back(line1[a]);
}

cout<<" Students from match file:"<<endl;  
for(int i=0;i<matchArr.size();i++){
   cout<<matchArr[i]<<endl;      
}

cout<<" Total number of students Interviewed:"<<totalInterviewed;

cout<<" Students Not matched list:"<<endl;  
for(int i=0;i<noMatch.size();i++){
    cout<<noMatch[i]<<endl;      
}
return 0;

  
  
  
  
}