Question: Restaurant database Write a program that uses a struct named Restaurant to store information about a restaurant. You will be extending the previous lab to

Restaurant database

Write a program that uses a struct named Restaurant to store information about a restaurant. You will be extending the previous lab to read restaurant data from an input file into an array (size 50) of Restaurant structs. The program will contain the following files:

Restaurant.h - Struct definition and related function declarations Restaurant.cpp - Related function definitions main.cpp - main() function restaurant.txt - Text file with restaurant information 

(1) Build the Restaurant struct with the following specifications (Restaurant.h and Restaurant.cpp):

 char restaurantName[101] char foodType[101] double rating; 

You may NOT use strings.

(2) Create the following functions (Restaurant.h and Restaurant.cpp):

void loadValues(ifstream &inFile, Restaurant rests[], int &numRests); // reads from file, populates the array, updates the number of restaurants in the array

void printValues(Restaurant rests[], int numRests); // prints the contents of the array

(3) In main() (main.cpp), open the restaurants.txt file and pass to the loadValues() function to read the restaurant data into the array. Then call the printValues() function to print out the list of restaurants.

(4) Program input and output:

File input, restaurant.txt:

Swagath;Indian;5.0 Don Pablos;Mexican;4.0 Mama Mias;Italian;4.5 Mod Pizzeria;Pizza;4.3 Joes Boathouse;American;4.8 NYHouse Pizzeria;Pizza;4.9 

Program output:

Swagath Indian 5.0 Don Pablos Mexican 4.0 Mama Mias Italian 4.5 Mod Pizzeria Pizza 4.3 Joes Boathouse American 4.8 NYHouse Pizzeria Pizza 4.9 

Use the setw() manipulator to create columns for printing - 25 characters for Restaurant Name and 15 characters for Food Type.

(5) Notes:

Make sure to have #include in your Restaurant.cpp file.

Make sure to have the statement, cout << fixed << showpoint << setprecision(1); in your printValues() function.

Make sure the prompts and the output look the same as the above examples.

Use cin.getline(varName, 101); to read restaurant names and food types.

Have a newline (endl) at the end of every prompt to match the output.

main.cpp

#include #include #include

#include "Restaurant.h" using namespace std;

int main() { Restaurant restaurants[50]; int numRests = 0; ifstream inFile; /* add your code here */ return 0; }

Restaurant.cpp

#include "Restaurant.h" using namespace std;

/* add function loadValues() */

/* add function printValues() */

Restaurant.h

#ifndef RESTAURANT_H #define RESTAURANT_H #include #include #include #include

using namespace std;

/* Define the Restaurant struct here */

/* Add function prototypes */

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!