Help with this C++ A small private elementary school would like to hire you to w
ID: 3821939 • Letter: H
Question
Help with this C++A small private elementary school would like to hire you to write a C++ program that stores students’ emergency phone numbers for school purposes. The students’ are required to provide the school with 3 phone numbers in case of an emergency. a. Phone: Specify a structure named Phone to store the area code, prefix, and last four digits of the phone number (suffix). You will use this structure as the data type for the required phone numbers in the StudentPhoneRecord structure. b. Specify a structure named StudentPhoneRecord to store the following data for each student: 1. Name 2. Home Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 3. Emergency Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 4. Student’s Doctor Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) c. Specify a one-dimensional array to store the student phone information records. Set the maximum number of student records to 50 (the school can only accommodate 50 students each school year), but let the user specify how many student records need to be entered. d. Use main( ) as your driver function. The program does not need to be repeatable. e. Write appropriate functions that main( ) calls to accomplish the following tasks: 1. Read the number of students in the school. 2. Read and store the name and required phone numbers for each student. 3. Display each student’s name and required phone numbers. Sample Input: Number of students (must be a positive number less than or equal to 50) = ? 3 Please enter the information for student 1. Name: Mary Jones Home Phone: Area Code: 501 Prefix: 329 Suffix: 4823 Emergency Phone: Area Code: 870 Prefix: 345 Suffix: 1120 Doctor Phone: Area Code: 501 Prefix: 329 Suffix: 7800 Please enter the information for student 2. Name: Lisa Mills Home Phone: Area Code: 870 Prefix: 345 Suffix: 6786 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 7654 Doctor Phone: Area Code: 654 Prefix: 445 Suffix: 3333 Please enter the information for student 3. Name: Mike Hester Home Phone: Area Code: 501 Prefix: 450 Suffix: 6789 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 5674 Doctor Phone: Area Code: 870 Prefix: 345 Suffix: 7654 Sample Output: The Student Phone report is: Mary Jones Home: 501-329-4823 Emergency: 870-345-1120 Doctor: 501-329-7800 Lisa Mills Home: 870-345-6786 Emergency: 501-234-7654 Doctor: 654-445-3333 Mike Hester Home: 501-450-6789 Emergency: 501-234-5674 Doctor: 870-345-7654 Help with this C++
A small private elementary school would like to hire you to write a C++ program that stores students’ emergency phone numbers for school purposes. The students’ are required to provide the school with 3 phone numbers in case of an emergency. a. Phone: Specify a structure named Phone to store the area code, prefix, and last four digits of the phone number (suffix). You will use this structure as the data type for the required phone numbers in the StudentPhoneRecord structure. b. Specify a structure named StudentPhoneRecord to store the following data for each student: 1. Name 2. Home Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 3. Emergency Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 4. Student’s Doctor Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) c. Specify a one-dimensional array to store the student phone information records. Set the maximum number of student records to 50 (the school can only accommodate 50 students each school year), but let the user specify how many student records need to be entered. d. Use main( ) as your driver function. The program does not need to be repeatable. e. Write appropriate functions that main( ) calls to accomplish the following tasks: 1. Read the number of students in the school. 2. Read and store the name and required phone numbers for each student. 3. Display each student’s name and required phone numbers. Sample Input: Number of students (must be a positive number less than or equal to 50) = ? 3 Please enter the information for student 1. Name: Mary Jones Home Phone: Area Code: 501 Prefix: 329 Suffix: 4823 Emergency Phone: Area Code: 870 Prefix: 345 Suffix: 1120 Doctor Phone: Area Code: 501 Prefix: 329 Suffix: 7800 Please enter the information for student 2. Name: Lisa Mills Home Phone: Area Code: 870 Prefix: 345 Suffix: 6786 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 7654 Doctor Phone: Area Code: 654 Prefix: 445 Suffix: 3333 Please enter the information for student 3. Name: Mike Hester Home Phone: Area Code: 501 Prefix: 450 Suffix: 6789 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 5674 Doctor Phone: Area Code: 870 Prefix: 345 Suffix: 7654 Sample Output: The Student Phone report is: Mary Jones Home: 501-329-4823 Emergency: 870-345-1120 Doctor: 501-329-7800 Lisa Mills Home: 870-345-6786 Emergency: 501-234-7654 Doctor: 654-445-3333 Mike Hester Home: 501-450-6789 Emergency: 501-234-5674 Doctor: 870-345-7654
A small private elementary school would like to hire you to write a C++ program that stores students’ emergency phone numbers for school purposes. The students’ are required to provide the school with 3 phone numbers in case of an emergency. a. Phone: Specify a structure named Phone to store the area code, prefix, and last four digits of the phone number (suffix). You will use this structure as the data type for the required phone numbers in the StudentPhoneRecord structure. b. Specify a structure named StudentPhoneRecord to store the following data for each student: 1. Name 2. Home Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 3. Emergency Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 4. Student’s Doctor Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) c. Specify a one-dimensional array to store the student phone information records. Set the maximum number of student records to 50 (the school can only accommodate 50 students each school year), but let the user specify how many student records need to be entered. d. Use main( ) as your driver function. The program does not need to be repeatable. e. Write appropriate functions that main( ) calls to accomplish the following tasks: 1. Read the number of students in the school. 2. Read and store the name and required phone numbers for each student. 3. Display each student’s name and required phone numbers. Sample Input: Number of students (must be a positive number less than or equal to 50) = ? 3 Please enter the information for student 1. Name: Mary Jones Home Phone: Area Code: 501 Prefix: 329 Suffix: 4823 Emergency Phone: Area Code: 870 Prefix: 345 Suffix: 1120 Doctor Phone: Area Code: 501 Prefix: 329 Suffix: 7800 Please enter the information for student 2. Name: Lisa Mills Home Phone: Area Code: 870 Prefix: 345 Suffix: 6786 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 7654 Doctor Phone: Area Code: 654 Prefix: 445 Suffix: 3333 Please enter the information for student 3. Name: Mike Hester Home Phone: Area Code: 501 Prefix: 450 Suffix: 6789 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 5674 Doctor Phone: Area Code: 870 Prefix: 345 Suffix: 7654 Sample Output: The Student Phone report is: Mary Jones Home: 501-329-4823 Emergency: 870-345-1120 Doctor: 501-329-7800 Lisa Mills Home: 870-345-6786 Emergency: 501-234-7654 Doctor: 654-445-3333 Mike Hester Home: 501-450-6789 Emergency: 501-234-5674 Doctor: 870-345-7654 A small private elementary school would like to hire you to write a C++ program that stores students’ emergency phone numbers for school purposes. The students’ are required to provide the school with 3 phone numbers in case of an emergency. a. Phone: Specify a structure named Phone to store the area code, prefix, and last four digits of the phone number (suffix). You will use this structure as the data type for the required phone numbers in the StudentPhoneRecord structure. b. Specify a structure named StudentPhoneRecord to store the following data for each student: 1. Name 2. Home Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 3. Emergency Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) 4. Student’s Doctor Phone Number. (Use the structure data type Phone. Refer to Nested Structures.) c. Specify a one-dimensional array to store the student phone information records. Set the maximum number of student records to 50 (the school can only accommodate 50 students each school year), but let the user specify how many student records need to be entered. d. Use main( ) as your driver function. The program does not need to be repeatable. e. Write appropriate functions that main( ) calls to accomplish the following tasks: 1. Read the number of students in the school. 2. Read and store the name and required phone numbers for each student. 3. Display each student’s name and required phone numbers. Sample Input: Number of students (must be a positive number less than or equal to 50) = ? 3 Please enter the information for student 1. Name: Mary Jones Home Phone: Area Code: 501 Prefix: 329 Suffix: 4823 Emergency Phone: Area Code: 870 Prefix: 345 Suffix: 1120 Doctor Phone: Area Code: 501 Prefix: 329 Suffix: 7800 Please enter the information for student 2. Name: Lisa Mills Home Phone: Area Code: 870 Prefix: 345 Suffix: 6786 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 7654 Doctor Phone: Area Code: 654 Prefix: 445 Suffix: 3333 Please enter the information for student 3. Name: Mike Hester Home Phone: Area Code: 501 Prefix: 450 Suffix: 6789 Emergency Phone: Area Code: 501 Prefix: 234 Suffix: 5674 Doctor Phone: Area Code: 870 Prefix: 345 Suffix: 7654 Sample Output: The Student Phone report is: Mary Jones Home: 501-329-4823 Emergency: 870-345-1120 Doctor: 501-329-7800 Lisa Mills Home: 870-345-6786 Emergency: 501-234-7654 Doctor: 654-445-3333 Mike Hester Home: 501-450-6789 Emergency: 501-234-5674 Doctor: 870-345-7654
Explanation / Answer
Hi,
I have completed the entire program but there is one error that I m getting for the getline function. Please try to run it. It may work for you. I could not look at the error as time is closing-
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <iterator>
using namespace std;
struct StudentPhoneRecord
{
char name[20] ;
char Homephone[3][30];
char Emergencyphone[3][30];
char Doctorphone[3][30];
};
int main()
{
int MAXSIZE=50,num;
cout<<"Number of students (must be a positive number less than or equal to 50) = ? "<<endl;
cin>>num;
if(num<=MAXSIZE) {
StudentPhoneRecord StudentPhoneRecord[num];
int i;
for(i=0; i<num; i++)
{
cout<<"Please enter the information for student "<<i<<endl;
getline(cin,StudentPhoneRecord[i].name);
cout<<"Home Phone:"<<endl;
cout<<"Area Code: ";
getline(cin,StudentPhoneRecord[i].Homephone[0]);
cout<<"Prefix: ";
getline(cin,StudentPhoneRecord[i].Homephone[1]);
cout<<"Suffix: ";
getline(cin,StudentPhoneRecord[i].Homephone[2]);
cout<<"Emergency Phone:"<<endl;
cout<<"Area Code: ";
getline(cin,StudentPhoneRecord[i].Emergencyphone[0]);
cout<<"Prefix: ";
getline(cin,StudentPhoneRecord[i].Emergencyphone[1]);
cout<<"Suffix: ";
getline(cin,StudentPhoneRecord[i].Emergencyphone[2]);
cout<<" Doctor Phone:"<<endl;
cout<<"Area Code: ";
getline(cin,StudentPhoneRecord[i].Doctorphone[0]);
cout<<"Prefix: ";
getline(cin,StudentPhoneRecord[i].Doctorphone[1]);
cout<<"Suffix: ";
getline(cin,StudentPhoneRecord[i].Doctorphone[2]);
cout<<"The Student Phone report is:"<<endl;
int i;
for(i=0; i<num; i++)
{
cout<<StudentPhoneRecord[i].name<<endl;
cout<<"Home : "<<StudentPhoneRecord[i].Homephone[0]<<"-"<<StudentPhoneRecord[i].Homephone[1]<<"-"<<StudentPhoneRecord[i].Homephone[0];
cout<<"Emergency : "<<StudentPhoneRecord[i].Emergencyphone[0]<<"-"<<StudentPhoneRecord[i].Emergencyphone[1]<<"-"<<StudentPhoneRecord[i].Emergencyphone[0];
cout<<"Doctor : "<<StudentPhoneRecord[i].Doctorphone[0]<<"-"<<StudentPhoneRecord[i].Doctorphone[1]<<"-"<<StudentPhoneRecord[i].Doctorphone[0];
}
}
else {
cout<<"The entered number exceeds the maximu limit";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.