Question

*Note: Include the following set of comments at the top of your source code for all assignments A...

*Note: Include the following set of comments at the top of your source code for all assignments

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 (ex. 501), prefix (ex. 336), and last four
digits of the phone number (suffix –> ex. 5674). You will use this structure as the data type for the
required phone numbers in the StudentPhoneRecord structure. (See lecture notes concerning a
“structure within a structure” or Section 11.6 in Chapter 11 e-text.)
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. (Perform input validation for the number of students.)
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

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

If you have any doubts, please give me comment...

#include<iostream>

using namespace std;

struct Phone{

int areaCode;

int prefix;

int suffix;

};

struct StudentPhoneRecord{

string name;

Phone homePhone;

Phone emergencyPhone;

Phone doctorPhone;

};

#define MAX_SIZE 50

int main(){

StudentPhoneRecord students[MAX_SIZE];

int n;

cout<<"Number of students (must be a positive number less than or equal to 50) = ? ";

cin>>n;

for(int i=0; i<n; i++){

cout<<"Please enter the information for student "<<(i+1)<<"."<<endl;

cout<<"Name: ";

getline(cin, students[i].name);

getline(cin, students[i].name);

cout<<"Home Phone:"<<endl;

cout<<"Area Code: ";

cin>>students[i].homePhone.areaCode;

cout<<"Prefix: ";

cin>>students[i].homePhone.prefix;

cout<<"Suffix: ";

cin>>students[i].homePhone.suffix;

cout<<"Emergency Phone:"<<endl;

cout<<"Area Code: ";

cin>>students[i].emergencyPhone.areaCode;

cout<<"Prefix: ";

cin>>students[i].emergencyPhone.prefix;

cout<<"Suffix: ";

cin>>students[i].emergencyPhone.suffix;

cout<<"Doctor Phone:"<<endl;

cout<<"Area Code: ";

cin>>students[i].doctorPhone.areaCode;

cout<<"Prefix: ";

cin>>students[i].doctorPhone.prefix;

cout<<"Suffix: ";

cin>>students[i].doctorPhone.suffix;

}

cout<<"The Student Phone report is:"<<endl;

for(int i=0; i<n; i++){

cout<<students[i].name<<endl;

cout<<"Home: "<<students[i].homePhone.areaCode<<"-"<<students[i].homePhone.prefix<<"-"<<students[i].homePhone.suffix<<endl;

cout<<"Emergency: "<<students[i].emergencyPhone.areaCode<<"-"<<students[i].emergencyPhone.prefix<<"-"<<students[i].emergencyPhone.suffix<<endl;

cout<<"Doctor: "<<students[i].doctorPhone.areaCode<<"-"<<students[i].doctorPhone.prefix<<"-"<<students[i].doctorPhone.suffix<<endl;

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
*Note: Include the following set of comments at the top of your source code for all assignments A...
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
  • 1.. All following elements have been identified as important to supporting school’s level of involvement with...

    1.. All following elements have been identified as important to supporting school’s level of involvement with law enforcement EXCEPT: A. The school and local law enforcement have developed a memorandum of agreement, (MOA), defining the roles and responsibilities of both. B. The school threatens children with punishment from law enforcement officials for even the most minor infractions. C. The school has developed and maintained an effective relationship with law enforcement. D. The school reports incidents of crime and violence to...

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
ADVERTISEMENT