I need help with this program using c++ language!
CS 317
Program Assignment
Name Arrange
You are to write a program that will read in each person’s name and print out the results. The list has been collected form different places and the names are not in some standard format. A person’s last name may appear last or it may appear first. A label has been associated with each name to identify where the last name appears. Either “surname” or “lastname” appears just before a person’s last name. The other will be his first name followed by optionally middle initial or name. Capitalize the first letters of each part of a name. Examples of inputs are given below.
Read in the names, and arrange them with the last name first, followed by a comma, followed by the first name and his middle name or initial if it exist.
Input file: namesLast.txt
Example input
tom archer lastname jones
lastname luewey Huewey dewy
See More surname Or-less
Example output (Sorted):
Jones, Tom Archer
Luewey, Huewey Dewy
Or-less, See More
This is the data input file: namesLat.txt
lastname Taylor marie denise james wilis surname thomas Stone Rock lastname Brown surname lea high lee stephens jabcobs lastname reynolds lastname russell mack hussell surname Lewis Michelle Tee john mark surname marshall lastname Moto ah sey o e lastname vey Twosee ore surname knocktosee surname finitee two N lastname ghigher Eve N T tow surname jammer Uh nuther lastname one surname Lotts lue Knew Ah C lastname moto lastname phinshed Just about Thee last surname own
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;
// function prototype
string capitalizeWord(string);
int main()
{
vector<string> names;
string line;
ifstream inFile("namesLat.txt");
if(!inFile.is_open())
{
cout << "Error in opening namesLat.txt" << endl;
exit(0);
}
while(getline(inFile, line))
{
stringstream ss(line);
vector<string> tokens;
string token;
// read each line from file
while(getline(ss, token, ' '))
{
tokens.push_back(token);
}
// capitalize all the tokens
for(int i = 0; i < tokens.size(); i++)
{
tokens[i] = capitalizeWord(tokens[i]);
}
// search for the word "Lastname" or "Surname"
// the index of the next word is the surname
string surname = "";
for(int i = 0; i < tokens.size(); i++)
{
if(tokens[i].compare("Lastname") == 0 || tokens[i].compare("Surname") == 0)
{
surname = tokens[i + 1];
// set surname index and after index equal to ""
tokens[i] = "";
tokens[i + 1] = "";
}
}
// using a for loop, append all the tokens which are not blank
// to construct the firstname and middlename (if any)
stringstream resStream;
string result = "";
for(string s : tokens)
{
if(s.compare("") != 0)
{
resStream << s << " ";
}
}
// finally, add the surname before the name to finalise the name
result = surname + ", " + resStream.str();
// add the full name to the list of names
names.push_back(result);
}
// finally, print all the names from the list
cout << "All names:\n";
for(string name : names)
{
cout << name << endl;
}
return 0;
}
// this method returns a capitalised version of the input string "s"
string capitalizeWord(string s)
{
s[0] = toupper(s[0]);
return s;
}
***************************************************************** SCREENSHOT **********************************************************
I need help with this program using c++ language! CS 317 Program Assignment Name Arrange You...
Do WITHOUT #include<sstream> C++ You are to write a program that will read in upto 15 names, rearrange each person's name. The list has been collected from different places and the names are not in some standard format. A person's last name may appear last or it may appeaer first. A label has been associated with each name to identify where the last name appears. Either "surname" or "lastname" appears just before a person's last name. The other will be...
Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...
C++. You are to write a program to set up a data base for a phone index. The key will be a person’s name and the table will supply the phone number. The data base must be implemented as a hash table with the names as the key. The format will be a person name (multiple parts) followed by a phone number. Example: John Doe 601-5433 or O E Vay 921-1234. Only one name one phone number will be on...
This is Visual Basic program, thank you for your help In this assignment, you'll start a new Windows Forms application. Assume we have the data shown below: Names_first={"jack","marjy","tom","luke","sam","al","joe","miky","lu"} Name_last={"jones","ety","fan","spence","amin",sid","bud","ant","ben"} Amounts={234.45,8293.1,943.25,27381.0,271.39,7436.12,2743.0,1639.95,2354.2} The above will allows us to emulate reading data from a file, which we will learn in the next unit. For now, we will assume the data above has been read from a file. We need to process this data in fast way. For that purpose, we need to: Declare...
Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...
I need a C++ program like this please! and please follow all instructions! Thanks so much! A menu-driven program with 3 choices: Names Rearranger, Number Validator, or Exit Menu Option 1: Name Rearranger: 1. Input ONE STRING from the user containing first name, middle name, and last name. ie, "John Allen Smith". USE THE GETLINE function. (Not cin) 2. Loop through the string and validate for a-z or A-Z or . If the name has any other characters, then ask...
Need help!!! I need two programs that use one common database.. One program using a Visual Basic windows form using textboxes for data input (first name, last name, phone, email) and it should save the info into an SQL database when a save button is clicked. Second program using a C# windows form that has a drop down menu with all the names that have been saved into the database, when one name is clicked all their information should pop...
need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data file – It has: player ID, player first name, middle initial, last name soccer.txt – Player information file – It has: player ID, goals scored, number of penalties, jersey number output file - formatted according to the example provided later in this assignment a) Define a struct to hold the information for a person storing first name, middle initial, and last name). b) Define...
C++ I need a program that will read a list of names from a data file and store them in an array. You will then sort the array by last name using a quicksort, and display the results, one name per line.Each line has a first name and a last name.The file has 40 names in it right now, but the array should be able to accommodate up to 50 names.txt***************************************************** Barbara Wright Ian Chesterton Steven Taylor Sara Kingdom Dodo...
Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...