Question

Write a C++ program that stimulates a questionnaire to find a roommate from your computer class....

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 basic
C++ language. // COMMENT IS Mandatory.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <fstream>
#include <iostream>

#include <string>
using namespace std;


int main () {
  
//we will use this variable take input from user
string data;
//we will use this variable to keep count of choices matching our requirement. We will do this by incrementing it each time choice matches.
int count;
int NumberOfCandidates=0;
//will use to take input of choice from user
int userinput;




do {
    //this do-while loop will run each time for evey new candidate. So we will initialise count to 0 everytime.
count=0;
//showing meassage to user to choose any
cout <<"Please enter command to proceed: "<< endl;
cout <<" TO inteview new candidate press 'i' "<< endl;
cout <<"To Display Number of candidates Interviewed 'n'"<< endl;
cout <<"To Display all mattching candidate from matchfile 'd'"<< endl;

cout <<"Quit Program press 'q'"<< endl;
//taking input from user
cin >> data;
//comparing input to call perform accordingly

//If new candidate . we will start questioning
if (data=="i") {
    //varrible will be incremented each time I pressed. To calculate number of caandidates interviewed
    NumberOfCandidates++;
//ask question
cout << "How often do you clean ,Enter in terms of Number of days .(example 5)?" << endl;
//take input of candidate
cin >> userinput;
//will increment count if he does cleaning in 2 days or less.
if(userinput<=2){
   count++;
   cout << count;
   }
   //ask question
   cout << "What do you do on the weekends?(Press 1 for Play outdoor games,2 for indoor games,3 forr study,4 for go home,5 other than these)" << endl;
   //take input of candidate
cin >> userinput;
//will increment count if he does does things Interviewer like.
if(userinput==1 ||userinput==2||userinput==3||userinput==4){
   count++;
  
   }
   //ask question
cout << "Do you like to have friends over or keep the party outside?.Press 1 if keep outside.Else press 2" << endl;
//take input of candidate
cin >> userinput;
//will increment count if he does does things Interviewer like.
if(userinput==1 ){
   count++;
  
   }
   cout << "Do you smoke?.Press 1 Yes.Else press 2" << endl;
cin >> userinput;
if(userinput==2 ){
   count++;
  
   }
   cout << "How often do you drink at home? Press 1 If you donot drink,If once in month press 2.Else 3"<< endl;
cin >> userinput;
if(userinput==1 ||userinput==2 ){
   count++;
}
cout << "Do you have references?Press 1 If .Else 2"<< endl;
cin >> userinput;
if(userinput==1 ){
   count++;
}
   cout << "What time do you go to bed?Press 1 If before 11 .Else 2"<< endl;
cin >> userinput;
if(userinput==1 ){
   count++;
}
cout << "Do you have any pets?Press 1 If.Else 2"<< endl;
cin >> userinput;
if(userinput==2 ){
   count++;
}
  
cout << "What is your major hobby??Press 1 If Cricket or football. Press 3 if Programming. Else 3"<< endl;
cin >> userinput;
if(userinput==1 ||userinput==2||userinput==3){
   count++;
  
}
  
//If count has become 5 or more. That means candidate has choices matching Interviewer choices.We will do entry in matchfile.

   if(count>=5){
   
    // open a file in write mode.
ofstream outfile;
       //std::ios_base::app will open file in append mode. You can remove this .If you want to overwrite it.
outfile.open("matchfile.dat",std::ios_base::app);
//will take candidate name in data variable
cout << "Enter your name: ";
cin >> data;
// write inputted data into the file.
outfile << data << endl;
//close the file
outfile.close();
   }
   //If count is less than 5 .That mean Candidate doesnot have Interviewer choices
   else{
      cout << "Thanks for Comming";
   }
}

//If user input was "d". We will read the matchfile
   else if (data=="d") {
  
// open a file in read mode.
ifstream myfile ("matchfile.dat");


cout << "Reading from the file" << endl;
//reading file each line and printing it on screen
while ( getline (myfile,data) )
{
cout << data << '\n';
}
//close the file

myfile.close();
}
//to display number of candidates Interviewed
else if (data=="n") {
cout <<NumberOfCandidates<< endl;
}
//if choice is q. We quit
else if (data=="q") {
cout <<"Exiting Prgram"<< endl;
break;
}

} while (true);

  
return 0;
}

Please enter command to proceed TO inteview new candidate press i To Display all mattching candidate from matchfile d Qui

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that stimulates a questionnaire to find a roommate from your computer class....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • C# Write a program that takes a list of information and grades of the students of...

    C# Write a program that takes a list of information and grades of the students of a class and perform some processing. Take the following steps to write the program. The program must give the user two options such as a menu. At the beginning of the program must ask the following from the user: Which task you want to do (choose an option between 1-2), 1- Entering new information 2- Searching a student If the user types something rather...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • Write a menu-driven C++ program to manage a class roster of student names that can grow...

    Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • C Program Assignment: 2-Add comments to your program to full document it by describing the most...

    C Program Assignment: 2-Add comments to your program to full document it by describing the most important processes. 3-Your variables names should be very friendly. This means that the names should have meaning related to what they are storing. Example: Instead of naming the variable that stores the hours worked for an employee in a variable called ‘x’ you should name it HoursWorked. 5-Submit your .c program (note that I only need your source code and not all files that...

  • Stuck on this computer science assignment Write a program that demonstrates binary searching through an array...

    Stuck on this computer science assignment Write a program that demonstrates binary searching through an array of strings and finding specific values in an corresponding parallel double array. In all cases your output should exactly match the provided solution.o. Provided files: Assignment.cpp - starter assignment with function prototypes companies.txt - file for program to read. earnings.txt - file for program to read. Input1.txt Input2.txt - Test these inputs out manually, or use stream redirection Input3.txt - These inputs are based...

  • Please write a C# program For this part of the lab, you'll be writing methods to...

    Please write a C# program For this part of the lab, you'll be writing methods to work with 1D arrays. We will expect you to know how to create an array, and store and retrieve information from them. Continue working in the same project and “Program.cs” file. You will be generating random numbers, but the class Random is part of the standard library (don’t need any additional using statements). You should consider developing the methods for this project incrementally. In...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT