Question
How to output my code to a the file out.txt? (using xcode) It's c++ //This project was created by John Doe on November 24 2017
How to output my code to a the file out.txt? (using xcode)
It's c++
//This project was created by John Doe on November 24 2017
//including directories
#include
#include
#include
#include
#include
using namespace std;
//Enums to be used later on
enum marriedStatus{
single = 'S',married = 'M',divorced='D'
};
enum genderOf{
female='F',male='M'
};
int main(){
//Reading file into program
ifstream infile;
infile.open("machineproblem6");
ofstream outfile("output.txt");
outfile.open("output.txt");
//Defining variables
char gender;
char marriageStatus;
string firstName;
string entireName;
string entireLine;
size_t pos;
char s[25];
char str[100];
string lastName;
int startPoint;
//Outputting title of output
cout< cout<<" "< //While loop until end of file to go over the several lines in file while(!infile.eof()){ //Read the file into variable infile.getline(str,100); //use substring to find both the gender and marriageStatus of the selected group of people gender=str[0]; marriageStatus=str[1]; //I got the idea for this set up from someone online to get rid of all the spaces and make the input easier to work with int j=0; for(int i=0;str[i]!='\0';i++){ //If the str letter isn't null, continue working through it if(str[i]==' ') //If it is equal to decremanate after going through the whole loop { while(str[i]!='\0'&&str[i]==' ')//If it is equal to a space and not null get incremenate { i++; } i--; } s[j++]=str[i]; if(str[i]==','&&str[i+1]!=' ') //if str is equal to ',' and a space before it add a space s[j++]=' '; } s[j]='\0'; //Set it to null entireName=(s+2);//Set entireName equal to the str excluding the first two characters //Find all letters before comma startPoint=entireName.find(','); //Input all the letters before comma into lastName lastName=entireName.substr(0,startPoint); //Input entireName into entireLine entireLine=entireName; //Input entireName into firstName firstName=entireName; //Find all letters after comma pos=firstName.find(','); //Erase all letters before comma firstName.erase(0,pos); //Only input the firstName and not middleName into the variable firstName firstName=firstName.substr(1,firstName.length()-2); //Inputing gender and marriageStatus if(gender==female){ if(marriageStatus==married){ string inFront; inFront="Mrs. "; firstName = (inFront+firstName); } else{ string inFront; inFront="Ms. "; firstName=(inFront+firstName); } } else if(gender==male){ string inFront; inFront="Mr. "; firstName=(inFront+firstName); } else{ return 0; } //Outputting Standardized Names cout< } outfile.close(); infile.close(); } /*www.stackoverflow.com/questions/24700561/how-do-i-remove-everything-in-a-string-prior-to-a-specific-word-in-c //www.chegg.com/homework-help/questions-and-answers/already-assignment-output-wrong-first-line-output-right-rest- isnt-m-intro-c-course-advance-q25341207*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started