Question

Write a menu-driven C++ program to manage a class roster of student names that can grow...

Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Marcela Nogueira[ENTER] Array size: 2, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: l[ENTER] Student Roster -------------- Jonas-Gunnar Iversen Marcela Nogueira Array size: 2, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: d[ENTER] Enter the student name to delete: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: q[ENTER] Requirements Allow the menu options to be entered in either lower or upper case. Implement all the actions in the above menu -- add, delete and list. Use a dynamic array of strings to store the roster, with an initial capacity of 2. Double the array capacity when (a) you have a new student to add, and (b) size equals capacity. You do not need to shrink the array after deletes. The output table should have a column heading as shown above. Output the array size and capacity along with the output table. Hints You don't have to write functions for everything. You may just write code blocks in main, and if it makes sense for youto move any of them out of main and into functions (like a void function to cout a table of names), do so. Would the operations be best handled with a series of if/else statements, or a case/switch statement? There are some built-in string functions that convert to upper and lower case. What to Submit Submit your .cpp file and a screenshot of one run of the program that includes at least an "add" of a name and one "list" operation. Please answer with different person

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

CODE:

#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

    // Char double pointer array to save records;
    char **students_record = new char*[2];
    char choice;// choice
    int size = 0, capacity = 2;// capacity and size of array.
    int delcount = 0;// number of names deleted;
    bool quit = false;// variable to quit the program.
    string name;

    do {
        // display menu
        cout<<"ARRAY Size : "<<size-delcount<<" Capacity : "<<capacity<<endl
            <<"MENU\nA Add a student\nD Delete a student\nL List all students\nQ Quit\n...your choice : ";
        cin>>choice;
        switch(choice){
            case 'A':
            case 'a':
                cout<<"Enter the name of student to add : ";
                getline(cin, name);// To get the \n after the choice.
                getline(cin, name);// accept string with space;

                // if size is same as capacity then double the array using realloc.
                if(size == capacity) {
                    students_record = (char **)realloc(students_record, capacity * 2 *sizeof(*students_record));
                    capacity *= 2;
                }
                // copy students name.
                students_record[size] = new char[name.size()];
                strcpy(students_record[size],name.c_str());
                size++;
                break;
            case 'D':
            case 'd':
                cout<<"Enter the student name to delete: ";
                getline(cin, name);// accept \n after choice.
                getline(cin, name);// accept spaces

                for (int i = 0;i<size;i++) {
                    if(strcmp(name.c_str(),students_record[i])==0) {
                        // empty the deleted string when found.
                        strcpy(students_record[i],"");
                        // increase the delete count;
                        delcount++;
                    }
                }
                break;
            case 'L':
            case 'l':
                getline(cin, name);// accept the \n after choice
                cout<<"Student Roster\n---------------------\n";
                for (int i = 0; i< size; i++) {
                    // skip printing of records which are empty.
                    if(strcmp(students_record[i], "") != 0){
                        cout<<students_record[i]<<endl;
                    }
                }
                break;
            case 'Q':
            case 'q':
                // initialize quit to true for exiting the loop.
                quit = true;
                break;
        }
    }while(!quit);

    return 0;
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write a menu-driven C++ program to manage a class roster of student names that can grow...
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
  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • This program will store a roster of most popular videos with kittens. The roster can include...

    This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...

  • In C Program This program will store the roster and rating information for a soccer team. There w...

    In C Program This program will store the roster and rating information for a soccer team. There will be 3 pieces of information about each player: Name: string, 1-100 characters (nickname or first name only, NO SPACES) Jersey Number: integer, 1-99 (these must be unique) Rating: double, 0.0-100.0 You must create a struct called "playData" to hold all the information defined above for a single player. You must use an array of your structs to to store this information. You...

  • You are to write a program name Bank.java that maintains a list of records containing names...

    You are to write a program name Bank.java that maintains a list of records containing names and balance of customers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities:           a    Show all records           r     Remove the current record           f     Change the first name in the current record           l     Change the last name in the current record           n    Add a new record           d   ...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Write a C++ program to keep records and perform statistical analysis for a class of 20...

    Write a C++ program to keep records and perform statistical analysis for a class of 20 students. The information of each student contains ID, Name, Sex, quizzes Scores (2 quizzes per semester), mid-term score, final score, and total score. The program will prompt the user to choose the operation of records from a menu as shown below: ==============================================                                            MENU =============================================== 1. Add student records 2. Delete student records 3. Update student records 4. View all student records 5. Calculate...

  • 5.19 Ch 5 Program: Soccer team roster (Vectors) (C++) This program will store roster and rating...

    5.19 Ch 5 Program: Soccer team roster (Vectors) (C++) This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts) Ex:...

  • You will modify Project 3 to include a student struct. The struct should include 3 data...

    You will modify Project 3 to include a student struct. The struct should include 3 data members a char array (for the name), a char array (for the housing response), and an int (for units). The four functions will all need to be modified to take a pointer to a student struct. Make the necessary modifications to the code in the function body. You will also provide a menu interface for the user. The menu will initially allow the user...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last...

    write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last name and first name of the owner). Ask the user to input up to 10 Contacts (It may be less. The user should have the ability to stop inputting Contacts whenever he wishes). 3.This class will store a list of Contacts in a stack allocated array of default capacity 10. 4.You must be able to add new contacts to a list, delete old contacts,...

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