Question

C++ please Let's pretend that we can still go out to eat at a restaurant. Suppose...

C++ please

Let's pretend that we can still go out to eat at a restaurant. Suppose we have the job to make a program that accepts a dinner reservation. The information collected will be the name of the customer, the date for the reservation, the time for the reservation (good choice for a hierarchical struct), the number in the party, email address (for updates) and phone number. Define a hierarchical structure for a dinner reservation that will contain the above information. Using that structure declare variables for at least two dinner reservations. Write a program that accepts data, populates the variables and prints out the data for at least two reservations. You can modify the functions from this module to read the data and print the data. (NOTE: Editing the program we just did should make this pretty easy.)

Here are the functions and code from the module:

//  
// Examples of hierarchical structures and functions
//

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

1. Define the structure for date. It has to be defined prior to the structure that uses it.
struct date
{
        unsigned int month;
        unsigned int day;
        unsigned int year;
};

2. We will now make a modified version of the student_record structure by adding
a member for the birthdate. (I have also removed the enumeration type from the struct
and changed the type for exam and homework to double.) The birthdate can be inserted at
any location within student_record. Remember that the order of struct members does not matter.
Here is the modified student_record.

struct student_record
        {
                string firstname;
                string lastname;
                date birthdate;
                float gpa;
                double exam;
                double homework;
                float grade;
        };

// Function Prototypes go Here

int main(void) 
{

3. Declare some variables of type student_record. Let's use Alice and Bob again. Notice
that we cannot initialize these variables right now since they continue multiple items of
different types.

   // Variables of type student record
   student_record Alice, Bob;

4. Let's populate the members of Alice by typing in the data. The names are easily
entered just as in our previous example.

   cout << "Enter Student Data for Alice." << endl;
   cout << "First Name " << endl;
   cin >> Alice.firstname;

   cout << "Last Name " << endl; 
   cin >> Alice.lastname;

5. Now for birthdate. How do we handle the hierarchical structure? We have to use another dot.

   cout << "Enter birthdate as MM DD YYYY " << endl;
   cin >> Alice.birthdate.month >> Alice.birthdate.day >> Alice.birthdate.year;

6. When the birthdate is entered we have to access each of the three members (month, day
and year) individually. First we get Alice's birthdate using one dot (Alice.birthdate) . 
In order to "drill down" to the individual parts of the birthdate we have to use an
additional dot (Alice.birthdate.month).

7. Now let's fill out the remaining data for Alice.

   cout << "Enter gpa " << endl;
   cin >> Alice.gpa;

   cout << "Enter exam average " << endl;
   cin >> Alice.exam;

   cout << "Enter homework average " << Alice.homework;
   cin >> Alice.homework;

8. Compute Alice's numeric grade from exam and average

   Alice.grade = Alice.exam * 0.8 + Alice.homework * 0.2;

9. Finally let's print out all of Alice's data.

   cout << endl;
   cout << "Data Record for Alice " << endl;
   cout << Alice.firstname << "  " << Alice.lastname << endl;
   cout << "Birthdate: " << Alice.birthdate.month
        << setw(3) << Alice.birthdate.day 
        << setw(5) << Alice.birthdate.year << endl;
   cout << fixed << setprecision(1);
   cout << "Grade Point Average " << Alice.gpa << endl;
   cout << "Exam Avg. " << Alice.exam << endl;
   cout << "Homework avg. " << Alice.homework << endl;
   cout << "Grade " << Alice.grade << endl;

   cout << endl << endl;
   system("pause");
   return 0;
}
10. This completes the example. You should compile and run the program
entering data for Alice. We will get to Bob later.

Proceed to the next page where we will introduce functions.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE :

#include<iostream>
using namespace std;

//This is user defined data type called "struct"
struct restro{
   char name[30];
   int date;
   int time;
   int number;
   char email[30];
   int phn_number;
};
int main(){

//Array of objects
   restro r[100];
   int n;
   cout<<"Enter the reservations you want to make :";
   cin>>n;
   cout<<"Please Enter the Details";

//loop for taking input
   for(int i=0;i<n;i++){
       cout<<"\nReservation "<<i+1<<endl;
       cout<<"======================================================\n";
       cout<<"Enter the name :";
       cin>>r[i].name;
       cout<<"\nEnter the date of reservation : ";
       cin>>r[i].date;
       cout<<"\nEnter the time of reservation : ";
       cin>>r[i].time;
       cout<<"\nEnter the number : ";
       cin>>r[i].number;
       cout<<"\nEnter Email : ";
       cin>>r[i].email;
       cout<<"\nEnter your phone number : ";
       cin>>r[i].phn_number;
       cout<<"======================================================\n";
   }
   cout<<"\n\nDetails of the Reservation";

//loop for the output
   for(int i=0;i<n;i++){
       cout<<"\nReservation "<<i+1<<endl;
       cout<<"======================================================\n";
       cout<<"Name :"<<r[i].name;
       cout<<"\nDate of reservation : "<<r[i].date;
       cout<<"\nTime of reservation : "<<r[i].time;
       cout<<"\nNumber : "<<r[i].number;
       cout<<"\nEmail : "<<r[i].email;
       cout<<"\nYour phone number : "<<r[i].phn_number;
       cout<<"\n======================================================\n";
   }
}

Add a comment
Know the answer?
Add Answer to:
C++ please Let's pretend that we can still go out to eat at a restaurant. Suppose...
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
  • Need done in C++ Can not get my code to properly display output. Instructions below. The...

    Need done in C++ Can not get my code to properly display output. Instructions below. The code compiles but output is very off. Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a team. When the program runs, it should ask the user...

  • Objectives: The main objective of this assignment is checking students’ ability to implement membership functions. After...

    Objectives: The main objective of this assignment is checking students’ ability to implement membership functions. After completing this assignment, students will be able to:  implement member functions  convert a member function into a standalone function  convert a standalone function into a member function  call member functions  implement constructors  use structs for function overloading Problem description: In this assignment, we will revisit Assignment #1. Mary has now created a small commercial library and has managed...

  • please Code in c++ Create a new Library class. You will need both a header file...

    please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

  • IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data...

    IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest. The highest average should then be on the last row.. When you sort the average, you...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • can someone please double check my code here are the requirements please help me fulfill the...

    can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...

  • using C++ language!! please help me out with this homework In this exercise, you will have...

    using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...

  • Can someone please help me with this code? I'm writing in C++. Thank you in advance....

    Can someone please help me with this code? I'm writing in C++. Thank you in advance. Complete a program that represents a Magic Eight Ball (a Magic Eight Ball allows you to ask questions and receive one of several random answers). In order to complete this, you will need a couple of new functions. First, in order to get a line of input that can contain spaces, you cannot use cin, but instead will use getline: string question; cout <<...

  • c++, we have to write functions for the code given below and other instructions for it...

    c++, we have to write functions for the code given below and other instructions for it to compile. I am having issues understanding how to confront the problem and how to write functions and read the program so it can eventually be solved so it can be compiled 7/ * INSTRUCTIONS: Write two functions in the space // * indicated below. // * // * #1 => Find index of maximum value: Write a function that will // * find...

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