Question

anyone know why I can't find my output on Xcode? it compiles but it wont show...

anyone know why I can't find my output on Xcode? it compiles but it wont show me any output.

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void print(string rawName, string formattedName);

enum Married {
SINGLE, MARRIED, DIVORCED
};


Married isMarried(string s) {

Married married;

if (s == "M") {
married = MARRIED;
}
else if (s == "S") {
married = SINGLE;
}
else if (s == "D") {
married = DIVORCED;
}

return married;
}

string formatName(string gen, Married mar, string lN, string fN, string mI) {

string formattedString;

if (gen == "M") {
formattedString += "Mr. ";
}
else if (gen == "F" && (mar == 0|| mar == 2)) {
formattedString += "Ms. ";
}
else
formattedString += "Mrs. ";

formattedString += fN + " ";

if (mI != " ") {
formattedString += mI + " ";
}

formattedString += lN;

return formattedString;
}

void process() {

ifstream infile;
infile.open("mp6names.txt");

string gender;
//string maritalStatus;
string lastName;
string firstName;
string middleInit;
Married maritalStatus;
string strFull;

while (getline(infile, strFull)) {
gender = strFull.substr(0, 1);
maritalStatus = isMarried(strFull.substr(1, 1));
string str = strFull.substr(2);
string::size_type pos1 = str.find_first_not_of(" ");
string::size_type pos2 = str.find(",");

//Retrieve last name from line by using pos1 & pos2 variables
lastName = str.substr(pos1, (pos2 - pos1));

//to trim off last name from original string and then locate the first non-empty space in newString
string newStr = str.substr(pos2 + 1);
pos1 = newStr.find_first_not_of(" ");

//Locate first name
firstName = newStr.substr(pos1, newStr.substr(pos1).find(" "));

//Routine to find last instance of white space,
string findMidInit = str.substr((str.find_last_of(" ")) + 1);
if (findMidInit != " ") {
middleInit = findMidInit;
}

string formattedName = formatName(gender, maritalStatus, lastName, firstName, middleInit);

print(str, formattedName);
}
}

void print(string rawName, string formattedName) {

cout << "--------------------------------------------------------" << endl;
cout << "Unformatted name: " << rawName << endl;
cout << "Formatted name: " << formattedName << endl;
}

int main()
{
process();

return 0;
}

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

It may be because you do not have "mp6names.txt" file. In process function, program is taking input from "mp6names.txt" file. so, you need to have "mp6names.txt" file in your code directory.

e.g.

So, you can see that i have "mp6names.txt" file in code directory. my code file name is p.cpp.

And

Also, Make sure that your "mp6names.txt" file has right structure. so that your program is able to fetch data correctly.

I have created sample file as below:

First character is gender. i.e. Male(M) or Female(F)

Second character is Martial Status. i.e. M-> Married or S-> Single etc.

Then Name...

So the output with above "mp6names.txt" file using your code is below:

Add a comment
Know the answer?
Add Answer to:
anyone know why I can't find my output on Xcode? it compiles but it wont show...
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
  • i have problem where the address is not save to my file after i input a...

    i have problem where the address is not save to my file after i input a new address and exit it #include<string> #include<iostream> #include<fstream> #include<sstream> using namespace std; typedef struct date {    int day;    int month;    int year; }Date; typedef struct add {    string building;    string street;    string city;    string state;    string zip; }Address; typedef struct entry {    string firstName;    string lastName;    Address address;    string phNo;    Date...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • I can't get my code to work on xcode and give me an output. #include <conio.h> #include <cstdlib> #incl...

    I can't get my code to work on xcode and give me an output. #include <conio.h> #include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; // So "std::cout" may be abbreviated to "cout" //Declare global arrays int dummy1[10]; int dummy2[10]; int dummy3[10]; int universalSet[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //Function to return statement "Empty thread" when the resultant set is empty string isEmpty(int arr[]) { string...

  • Rework this project to include a class. As explained in class, your project should have its...

    Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...

  • Following class is only part of my program that uses a hash table to simulate a...

    Following class is only part of my program that uses a hash table to simulate a market's client database, client class is my main class which asks user to input client names and then creates a hash table which then users can look up client names. wasn't able to upload everything as it is too much code, but what I need is to modify my client class instead of me inputting data line by line, the program should read from...

  • Hello I need a small fix in my program. I need to display the youngest student...

    Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...

  • Please provide original Answer, I can not turn in the same as my classmate. thanks In...

    Please provide original Answer, I can not turn in the same as my classmate. thanks In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a “next” pointer. Textbook Type Attribute String title String author String ISBN Textbook* next Textbook Type Attribute String title String...

  • HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...

    HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS. Task 1: Enforcing const-ness throughout Your first job will be to go through all of the code and decide which functions should be declared const. You should find several places throughout the program where this makes sense. We will also make the id data member in the Customer class const , as once a customer has been created their ID will never...

  • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

    I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

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