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 program Your teacher want to find out who is the most hardworking student in class!...

    c program Your teacher want to find out who is the most hardworking student in class! They want to input the names according to the order they fell asleep, then print their names in the reverse order. Although you can create an array large enough to store all names, your teacher don’t want to waste our precious memory! The first line of the input is an integer x, which indicate the number of students in class. Then there are x...

  • PLEASE WRITE PROGRAM IN C NOT C++ THANKS Your program is only required to locate and...

    PLEASE WRITE PROGRAM IN C NOT C++ THANKS Your program is only required to locate and print to the console the smallest integer in an array of 10 integers. Thus, no user input will be involved. You should use the following decimal numbers for your array: {5, 7, 12, 3, 4, 9, 6, 11, 2, 10}. You may store them as decimal or hexadecimal. Your program needs to do only three things: 1. Traverse an array 2. Store the smallest...

  • Write a C++ console program that defines a class named Course that utilizes a dynamically allocated...

    Write a C++ console program that defines a class named Course that utilizes a dynamically allocated array. Do not use the vector class for this assignment. The Course class should define private data members for the name of the course, the number of students in the course, an array of student names (string*), and the capacity of the course (the array may not be full of students). Use pointer notation when dealing with the array. A 2-arg constructor should initialize...

  • 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...

  • Programmed in Java Pls - The other answer to this question is incorrect.: Your program should...

    Programmed in Java Pls - The other answer to this question is incorrect.: Your program should follow the below requirements: You will only need one class for this project called StudentReport in the package ilstu.edu In your class you will have the following instance variables: grades: a double 2d array that will hold the grades for all the students. Students: a 1d String array that will hold the names of all the students. In your class you will have the...

  • 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...

  • .Using OOP, write a C++ program that will read in a file of names. The file...

    .Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...

  • 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...

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