Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

/*

         Movie List Example 

         --Showing how to use vectors and structures

*/

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
 
using namespace std;
 
// define a struct for a Movie object
struct Movie               // It is common for the struct name to be capitalized
{
    string title = "";     // First member of structure - and initialized
    int year = 0;          // Second member of structure - and initialized
};
 
int main() 
{
    cout << "The Movie List program\n\n"
         << "Enter a movie...\n\n";
 
    // get vector of Movie objects
    vector<Movie> movie_list;          
    char another = 'y';
 
    while (tolower(another) == 'y') 
    {
        Movie movie;  // make temporary new (initialized) Movie object
 
        cout << "Title: ";
        getline(cin, movie.title);
 
        cout << "Year: ";
        cin >> movie.year;
 
        movie_list.push_back(movie);
 
        cout << "\nEnter another movie? (y/n): ";
        cin >> another;
        cin.ignore();           // only extract one character and ignore the rest (flush the buffer)
        cout << endl;
    }
 
    // display Movie objects in vector
    const int w = 10;
    cout << left
         << setw(w * 3) << "TITLE" 
         << setw(w)     << "YEAR" << endl;
    for (Movie movie : movie_list) 
    {
        cout << setw(w * 3) << movie.title
             << setw(w)     << movie.year << endl << endl;
    }
}
 
  • Using the attached code as a model, write a program where each student record is a structure that looks like this:

 

struct StudentRec

{

string last_name = "";          // Last name

string first_name = "";         // First name

int year_grad = 0;                  // Year expected to graduate

float gpa = 0.0;                       // Current gpa

}

  • The program should ask for the data to fill a studentRec of structure StudentRec and then ask y/n if they want to add another studentRec.
    • Each studentRec will go into the vector of type StudentRec called student_list.
  • After the student records have been entered into the vector student_list, find the average gpa of all the students in the vector.
  • Output all the student records and give the average gpa for the students. Use the iomanip tools to make the data look as nice a possible.
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education