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 the user to input again, repeat until valid input has been input.
3. Loop through the string and throw out extraneous blanks, ie "John Allen Smith" should become "John Allen Smith".
4. Create a third string with the names arranged as last first middle. ie, "Smith, John Allen".
5. Create a professional looking display with both the original input from the user, the name without blanks, and the name rearranged.
Menu Option 2: Number Validator:
This function will be used to validate numbers for improper characters, ie, 345.bb, which, if you input into a double would cause your program to crash.
1. Input ONE STRING from the user that represents a money value, ie, $345.55 USE THE GETLINE function. (Not cin)
2. Strip off any leading $$'s.
3. Loop through the string and validate for 0 - 9 or "." If the string has any other characters, then ask the user to input again, repeat until valid input has been input.
4. When you finally have valid input, convert the string to a double.
5. Display both the original input and the number as a double.
Use the string class functions to accomplish all of this. The string class is discussed in the 2nd half of the chapter.
***Use modular design in your program. Main calls functions. Main does not toil or sweat.
***This is very important Main function should have as little as possible.
#include <iostream>
#include <string.h>
#include<cstddef>
#include <stdio.h>
#include<stdlib.h>
using namespace std;
void menu() {
cout << "Main menu" << endl;
cout << "1. Names Re-arranger" << endl;
cout << "2. Number Validator" << endl;
cout << "3. Exit" << endl;
cout << "Enter Your Choice" << endl;
}
void NameRearranger() {
string name;
//getting a valid input
while (1) {
cout << "Enter your Name(allowed characters are a-z and A-Z
and spaces): " << endl;
fflush(stdin);
getline(cin, name);
int flag = 0;
for (int i = 0; i < name.length(); i++) {
if ((!isalpha(tolower(name[i]))) || (name[i] != ' ')) {
flag = 1;
break;
}
}
if (flag == 0)
break;
}
string name2;
int j = 0;
//removing extra spaces
for (int i = 0; i < name.length(); i++) {
if (isalpha(name[i])) {
name2[j] = name[i];
j++;
} else if (name[i] == ' ' && name[(i - 1)] != ' ') {
name2[j] = name[i];
j++;
}
}
//rearranging name
for (int i = name2.length(); i >= 0; i--) {
if (name2[i] == ' ') {
cout << "You Entered: " << endl;
cout << name << endl;
cout << "Name without blanks: " << endl;
cout << name2 << endl;
cout << "rearrange: " << endl;
cout << name2.substr(i);
cout << ", " << name2.substr(0, i);
}
}
}
void NumberValidator() {
string amt, amt1;
while (1) {
cout << "Enter Amount(allowed characters are 0-9 and .): "
<< endl;
fflush(stdin);
getline(cin, amt);
//removing $
if (amt[0] == '$') {
amt1 = amt.substr(1);
}
//validating number
int flag = 0;
for (int i = 0; i < amt1.length(); i++) {
if ((!isalnum(amt1[i])) || (amt1[i] != '.')) {
flag = 1;
break;
}
}
if (flag == 0)
break;
}
double amt2;
amt2 = atof (amt1.c_str());
cout << "You Entered: " << endl;
cout << amt << endl;
cout << "validated: " << endl;
cout << amt2 << endl;
}
int main() {
int ch;
while (ch != 3) {
menu();
fflush(stdin);
cin>>ch;
switch (ch) {
case 1:
NameRearranger();
break;
case 2:
NumberValidator();
break;
case 3:
cout << "Thank You" << endl;
return 0;
break;
default:
cout << "Invalid Input" << endl;
break;
}
}
return 0;
}
Please comment if you have any issue in understanding or running this program
I need a C++ program like this please! and please follow all instructions! Thanks so much!...
So Im here and im stuck. I need to figure out how to get the
character of the first name to be printed on a separate line and
the middle and last. is there a way where i can tell a my function
to stop once it hit " "? Please help.
I #include iostream 2 #include string using namespace i; string name 7 getline cin, name 4 int main ) cout<"Please enter your full name: " problem3.cpp 3Write a...
Topics c++ Do While loops cin.ignore Description Redo the last assignment with the following modifications: 1. When the program asks the user to enter a student name, the user will enter the full name (e.g. John Smith). Make changes to the program to accommodate that. 2. When the program asks the user to enter the test score, the user will enter the test score as before. However, make changes to the program so that it will check that the score...
I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...
I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account: Customer name Customer address City State ZIP code Telephone Account balance Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...
Help. Write a C++ program that determines which of a company's four divisions (North, South, East, West) has the greatest sales for the quarter. It should include three functions at a minimum: float getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, calls a validate() function that will validate the input, and then returns the value back to main(). This function should be called once for each division. void validate() is...
please I need help with the question:
Problem: Write a C++ program that reads each character
from a user input, extracts the character if it is a digit, and
calculates the sum of all the digits. The program stops reading the
user input when the new line character ‘\n’ is encountered. For the
output of the program, you should print each digit extracted from
the user input and the sum of all the digits.
(*The main difference between “cin >>...
C++
Hey, I really need help with this lab. I don't understand the
function part at all. It'll be great way for me to understand. Than
you
Functions and loops: Write a program that will ask the user which type of triangle they would like to draw on the characters. The choices are screen with left-top-big left-bottom-big right-top-big right-bottom-big Get the user's choice, ask how big it should be, and then draw the shape. After each successful drawing, ask the...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
//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...
C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record { int age; string name; }; int check(record r[], int n, string nm) { for (int i = 0; i < n;...