Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions