Question

Please Help, I will rate either way because of the effort. Description: help in c++, this...

Please Help, I will rate either way because of the effort.

Description: help in c++, this program should have 3 files GuessWho.cpp, Person.cpp, Person.h

  • This program will be a Guess Who game.
  • The program should
    • Read the first line of people.txt,
    • Use the contents to set the members of your Person object,
    • Print the Guess Who People heading,
    • Print the Person that you read earlier
    • Prompt the user for a feature (name, haircolor, hairtype, gender, glasses, eyecolor, or hat)
    • Print the value of that feature for the Person that you read
  • You must have a Person class:
    • Member variables for each of the features
    • Get/Set methods as needed
    • Method to print all of the features (each feature is in a field 10 characters wide)
    • Method to print the header (you can print each string 10 characters wide)
    • You may add additional methods as needed
  • Use functions, in addition to main(), as appropriate
  • The file with the people is called, people.txt. There is one person per line. Each line contains 7 strings separated by 1 or more tabs: name, hair color, hair type, gender, glasses, eye color, and hat.

-------------------------------------------------------

After completing the program test it with those examples.

Sample Run #1 (bold, underlined text is what the user types):

      name haircolor  hairtype    gender   glasses  eyecolor       hat
----------------------------------------------------------------------
      Jane     black  straight    female       yes     brown        no
Feature? name

Jane

Sample Run #2 (bold, underlined text is what the user types):

      name haircolor  hairtype    gender   glasses  eyecolor       hat
----------------------------------------------------------------------
      Jane     black  straight    female       yes     brown        no
Feature? haircolor

black

Sample Run #3 (bold, underlined text is what the user types):

      name haircolor  hairtype    gender   glasses  eyecolor       hat
----------------------------------------------------------------------
      Jane     black  straight    female       yes     brown        no
Feature? glasses

yes
0 0
Add a comment Improve this question Transcribed image text
Answer #1
GuessWho.cpp

#include <iostream>
#include <fstream>
#include "Person.h"
#include <sstream>  
#include <vector>
 
using namespace std;
 
 
int main() {
 
        ifstream file("people.txt");
        string line;
        getline(file, line);
        file.close();

 //split string by whitespace
        vector<string> result;
        istringstream iss(line);
        for (string s; iss >> s; )
                result.push_back(s);
 
        if (result.size() < 7) {
                cout << "not enough data in line 1";
                return 0;
        }
 
        Person p;
        p.setName(result[0]);
        p.setHaircolor(result[1]);
        p.setHairType(result[2]);
        p.setGender(result[3]);
        p.setGlasses(result[4]);
        p.setEyecolor(result[5]);
        p.setHat(result[6]);
        p.printHeader();
        p.printFeatures();
 
        string feature;
        cout << "Feature? ";
        cin >> feature;
 
        if (feature == "name") {
                cout << p.getName();
        }
        else if (feature == "haircolor") {
                cout << p.getHaircolor();
        }
        else if (feature == "hairtype") {
                cout << p.getHairType();
        }
        else if (feature == "gender") {
                cout << p.getGender();
        }
        else if (feature == "glasses") {
                cout << p.getGlasses();
        }
        else if (feature == "eyecolor") {
                cout << p.getEyecolor();
        }
        else if (feature == "hat") {
                cout << p.getHat();
        }
 
        return 0;
}

Person.h

#ifndef PERSON_H
#define PERSON_H
 
#include <iostream>
#include <iomanip>     //used for setw
#include <string>
using namespace std;
 
class Person {
private:
        string name, haircolor, hairtype, gender, glasses, eyecolor, hat;
 
public:
        void printFeatures();
        void printHeader();
        void setName(string val);
        void setHaircolor(string val);
        void setHairType(string val);
        void setGender(string val);
        void setEyecolor(string val);
        void setHat(string val);
        void setGlasses(string val);
 
        string getName();
        string getHaircolor();
        string getHairType();
        string getGender();
        string getEyecolor();
        string getHat();
        string getGlasses();
 
};
 
 
#endif
 

Person.cpp

#include "Person.h"
 
 
 
void Person::printFeatures() {
        cout << left;
        cout << setw(10) << name << setw(10) << haircolor << setw(10) << hairtype <<  setw(10) << gender << setw(10) << glasses << setw(10) << eyecolor
                << setw(10) << hat << endl;
}
 
void Person::printHeader() {
            //set field width to 10 char
        cout << left;
        cout << setw(10) << "Name" << setw(10) << "Haircolor" << setw(10) << "HairType" << setw(10) << "Gender" << setw(10) << "Glasses"
                << setw(10) << "Eyecolor" << setw(10) << "Hat" << endl;
 
                cout << string(70, '-') <<endl;
}
 
void Person::setName(string val) {
        name = val;
}
 
void Person::setHaircolor(string val) {
        haircolor = val;
}
 
void Person::setGender(string val) {
        gender = val;
}
 
 
void Person::setHairType(string val) {
        hairtype = val;
}
 
void Person::setEyecolor(string val) {
        eyecolor = val;
}
 
void Person::setHat(string val) {
        hat = val;
}
 
void Person::setGlasses(string val) {
        glasses = val;
}
 
 
string Person::getName() {
        return name;
}
string Person::getHaircolor() {
        return haircolor;
}
string Person::getHairType() {
        return hairtype;
}
string Person::getGender() {
        return gender;
}
string Person::getEyecolor() {
        return eyecolor;
}
string Person::getHat() {
        return hat;
}
string Person::getGlasses() {
        return glasses;
}
 

Code screenshots

GuessWho.cpp

#include <iostream> #include <fstream> #include Person.h #include <sstream> #include <vector> using namespace std; Dint maistring feature; cout << Feature? ; cin >> feature; if (feature == name) { cout << p.getName(); else if (feature == hairc

Person.h

E#ifndef PERSON_H #define PERSON H //used for setw Govou WN #include <iostream> #include <iomanip> #include <string> using na

Person.cpp

#include Person.h void Person::printFeatures() { cout << left; cout << setw(10) << name << setw(10) << haircolor << setw(10avoid Person::setHat(string val) { : hat = val; avoid Person::setGlasses (string val) { glasses = val; string Person::getName

Input File

people.txt - Notepad File Edit Format View Help Jane black straight abcdefg ghijkl no female yes yes black brown yes

Output

Name Haircolor HairType Gender Glasses Eyecolor Hat straight female yes brown no Jane black Feature? glasses yes

Add a comment
Know the answer?
Add Answer to:
Please Help, I will rate either way because of the effort. Description: help in c++, this...
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
  • Description: help in c++, this program should have 3 files, TestCat.cpp, Cat.cpp, Cat.h. Write a Cat...

    Description: help in c++, this program should have 3 files, TestCat.cpp, Cat.cpp, Cat.h. Write a Cat class to maintain the information about a Cat: name, age, color, furLength, weight. Note that name, color, and furLength are all strings. Age is an integer and Weight is a floating-point numbers. Then write a test program for that class. The test program should read in values for each feature of the cat, set those, and then print them using the Cat’s print method....

  • ​​​​​​This program will make Maze game. Please Help in c++ Prompt the user for a file...

    ​​​​​​This program will make Maze game. Please Help in c++ Prompt the user for a file that contains the maze. Read it into a two-dimensional array Remember you can use inputStream.get(c) to read the next character from the inputStream. This will read whitespace and non-whitespace characters Don’t forget to read the newline character at the end of each line Print the maze to the screen from your array You should include a ‘*’ in your maze to indicate where the...

  • Please help and follow instructions, c++ , let me know if there is any questions Description:...

    Please help and follow instructions, c++ , let me know if there is any questions Description: This program is part 1 of a larger program. Eventually, it will be a complete Flashcard game. For this part, the program will Prompt the user for a file that contains the questions – use getline(cin, fname) instead of cin >> fname to read the file name from the user. This will keep you in sync with the user’s input for later in the...

  • Help c++ Description: This program is part 1 of a larger program. Eventually, it will be...

    Help c++ Description: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This will help you prepare for next week Print the final messages of...

  • Help please, write code in c++. The assignment is about making a hangman game. Instructions: This...

    Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...

  • Please help in c++, follow the instructions, please. try to use pass by reference and pass...

    Please help in c++, follow the instructions, please. try to use pass by reference and pass by value if you could Description: Write a program that will input wind speed and temperature and output the wind-chill factor. W = 35.74 + 0.6215 ∗ T − 35.75 ∗ V 0.16 + 0.4275 ∗ T ∗ V 0.16 Your program should use at least 2 functions in addition to main. One that uses pass by reference parameters and prompts the user for...

  • Help needed on C++ program: Program Description: Complete the Ship, CruiseShip, and CargoShip program (#12 in...

    Help needed on C++ program: Program Description: Complete the Ship, CruiseShip, and CargoShip program (#12 in the 9th edition of the text). Read the specific method requirements in the text. Specific Requirements: • Create the Ship class. • Create CruiseShip and CargoShip classes that are derived from Ship. • Create a small tester cpp file that has an array of Ship pointers (one each of Ship, CruiseShip, and CargoShip). The program steps through the array, calling each object’s print method....

  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

  • I need help with the following. I need to write a program code in Java using...

    I need help with the following. I need to write a program code in Java using NetBeans. It is from How to Program Java book Chapter 2. This program should calculate the packing of Candles. First read: The number of candles The number of candles that fit in each case Then calculate and print: The number of full cases The number of candles left over (partial case) If this order is large (more than 5 full cases needed) An extra...

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