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 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
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.
Note: The language used is C++.
Code:
#include<bits/stdc++.h>
using namespace std;
//This function will list out all the students in the
array.
void listStudents(string *arr, int arraySize){
cout<<"Student Roster\n";
cout<<"---------------\n";
for(int i=0;i<arraySize;i++)
cout<<arr[i]<<"\n";
}
//This function adds a student to the string array.
//References of arr, capacity and arraySize are passed so that
changes are also reflected in main function.
void addStudent(string* &arr, int & capacity, int &
arraySize, string name){
//If array is full, double its capacity.
if(arraySize == capacity){
//Double the capacity.
capacity *= 2;
//Create a temp pointer and point
it to arr.
string *temp = arr;
//Now allocate arr with new array
of increased capacity.
arr = new string[capacity];
//Copy the content of temp to
arr.
for(int
i=0;i<arraySize;i++)
arr[i] =
temp[i];
//Delete temp.
delete[] temp;
}
//Add the student at the end.
arr[arraySize] = name;
arraySize++;
}
//This function deletes a student from the array.
void deleteStudent(string *arr, int & arraySize, string
name){
//index will store the index of student to be
deleted.
int index = arraySize;
for(int i=0;i<arraySize;i++){
if(arr[i] == name){
index = i;
break;
}
}
//Just shift every element to its left after the
index.
for(int i=index+1;i<arraySize;i++){
arr[i-1] = arr[i];
}
//Decrease the array size.
arraySize--;
}
int main(){
//Initialize capacity with 2.
int capacity = 2;
//Create a dynamic array of size = capacity.
string *arr = new string[capacity];
//Initialize array size with 0.
int arraySize = 0;
char option;
//Menu driven program begins here.
while(true){
//Prompt the user for input.
cout<<"Array size:
"<<arraySize<<", Capacity:
"<<capacity<<"\n";
cout<<"A - Add a
student\n";
cout<<"D - Delete a
student\n";
cout<<"L - List all
students\n";
cout<<"Q - Quit\n";
cout<<"Enter your choice:
";
cin>>option;
//Change the option to upper case
letter using ASCII conversion.
if(option >= 'a' &&
option <= 'z')
option -=
32;
string name;
//cin.ignore() is used to clear
input buffer.
cin.ignore();
switch(option){
case 'A':
cout<<"Enter the student name to add:
";
getline(cin, name);
//Add the student to the array.
addStudent(arr, capacity, arraySize,
name);
break;
case 'D':
cout<<"Enter the student name to delete:
";
getline(cin, name);
//Delete the student from the list.
deleteStudent(arr, arraySize, name);
break;
case 'L':
//List all the students present in the
array.
listStudents(arr, arraySize);
break;
case 'Q':
//End the program.
return 0;
default:
//It is an invalid input.
cout<<"Enter correct choice\n";
break;
}
}
return 0;
}
Code Snippets:
Sample Output:
Assignment Write a menu-driven C++ program to manage a class roster of student names that can...
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...
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 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 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, 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 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 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 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...
In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...
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...