Question

C++ Programming

Screen Shot 2021-11-12 at 2.19.29 PM.pngScreen Shot 2021-11-12 at 2.19.53 PM.png

PROGRAM DESCRIPTION

In this project, you have to write a C++ program to keep track of grades of students using structures and files.

You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.


The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle names, student ID (8 digits long), number of tests the student took, and the scores in those tests. Note that each item is separated by commas (‘,’), even the last score has a comma after it. Do not change this format.


The teacher has given 5 tests to each student, but not all students took all 5 tests. The minimum test score is dropped.

You are also provided a .cpp file: getNumber.cpp. It has a single function getNumber which gets the number of student records in the data file. You will need to call this function to create your dynamic arrays. Do not edit this file.


PROGRAM REQUIREMENTS

1. As with all projects in this course, your program’s output will display your name, your EUID, your e-mail address, the department name, and course number. This means that your program will print this information to the terminal (see the sample output).

2. Declare and initialize the following global parameters.

• A global integer constant of type integer to store the number of tests given by the teacher

and initialize it to 5.

• An enumeration constant with values Add, Remove, Display, Search, Results, and Quit, and assign integer values 1, 2, 3, 4, 5, and 6 to the data items, respectively. They represent

menu choice presented to the user.

• A structure named Student with the following members.

o Name of the student (DO NOT USE SEPARATE VARIABLES FOR FIRST NAME AND LAST NAME)

o Student ID of the student

o Number of tests taken by the student

o An integer pointer for a dynamic array to store the test scores for the student 

o Average of the test scores


3. In your main function:

• Display a menu for the user (SEE SAMPLE OUTPUT) that provides the user the following

choices.

o Add a new student record

o Remove an existing student record

o Display all records

o Search for a particular student record using student ID

o Export the results to a disk file

o Quit the program

Using a suitable message, ask the user to make the menu choice using an integer variable. 

Based on the value entered by the user for menu choice, design a switch-case block to implement the following requirements.

o You must use the enumeration constants to set up your cases.

o You must use a variable of your enumeration constant type for switching control. 

o If the user chooses to add a student record

Call the function add_Student

o If the user chooses to remove a student record

Using a suitable message, ask the user the student ID of the student to remove.

Call the function remove_Student and pass the student ID entered by the user.

o If the user chooses to display records 

Call the function display

o If the user chooses to search for a student

Using a suitable message, ask the user the student ID of the student to search for.

Call the function search and pass the student ID entered by the user.

o If the user chooses to export results to a disk file. 

Call the function exportResults.

o If the user choose to quit the program.

Exit the program with a suitable message.

o If the user chooses anything else, execute the default case to notify the user of an incorrect choice.

Using a suitable loop, ask the user for the choice again.

Your program must keep on looping until the user enters the incorrect choice.


  1. Write a function named add_Student. Inside the function:

Using a suitable message, prompt the user for the first name, the last name, the student ID, the number of tests taken and the test scores of a student.

HINT: The test scores is in a dynamic array and the size of the array is the number of tests. 

Allocate memory accordingly.

Open the data file student.dat and write the data of the student to the file maintaining the given format.

You must use the structure members to write the data to the file.

This function will be called by the main function.


5. Write a function named remove_Student. It has a parameter for the student ID of the student to be removed.

Inside this function, call function getNumber to get the current number of students in the data file.

Create a dynamic array of the structure type Student. Use the number of students in the data file for size of this dynamic array.

Open student.dat file for reading.

In a loop, read one line of the file at a time and store appropriate data in the dynamic array.

o While reading check if the student ID being read from the file matches the student ID of the student to be removed.

o If you find match, use a Boolean flag to store that you have found a match.

o Copy the entire file to your dynamic array whether or not you find a match. 

Close the file.

If you have found a match while reading:

o Open student.dat file for writing.

o Write the contents of the dynamic array into the file, only if the student ID does

not match the student ID to be removed. If you have not found a match while reading:

o Notify the user with a suitable message to indicate the student does not exist. 

Close the file.

This function will be called by the main function.


6. Write a function named display. Inside the function,

Using the getNumber function and a pointer of type Student, create a dynamic array to read the contents of the file into the dynamic array using a suitable loop.

Using a second loop, display the contents of the array in the following format:

o Allocate 30 spaces for the entire name

o Allocate 15 spaces for the student ID

o Allocate 5 spaces each for the test score

o You don’t need to display the number of tests

Close the file

This function will be called by the main function.


7. Write a function named search. This function accepts the student ID of the student to search. Inside the function:

• Open the data file for reading.

• Declare a pointer of type Student. You DO NOT need an array here.

• Using a suitable loop, read each line of the file and store the appropriate data into the appropriate members of the structure pointer.

• Check if the student ID being read from the file matches the student ID to search. If there is a match:

o Set a Boolean flag to true to indicate match has been found.

o Display the data corresponding data of the matched student using the following

format:

Allocate 30 spaces for the entire name

Allocate 15 spaces for the student ID

Allocate 5 spaces each for the test score

You don’t need to display the number of tests

• If the Boolean is false i.e. no match is found, display an appropriate message for the user,

• This function will be called by the main function.


8. Write a function named exportResults. Inside the function:

Open a data file named averages.dat for writing. This file will contain the averages of the test scores for each student along with the student ID.

Open student.dat for reading.

Create a dynamic array of type Students using a suitable pointer and calling the function getNumber to store the contents of the data file student.dat.

In a loop, read the contents of the file and store it in the dynamic array.

In a second loop, process each student at a time to compute the average as follows:

o Compute the sum of the test scores.

o Note that the minimum score is dropped. Call the function named findMinimum (see Step 9) to find the minimum score and subtract it from the total score.

o Divide the sum by an appropriate integer to compute the average.

oWrite the student ID and the average to the averages.dat file. The average

column should have one digit after the decimal point. 

Close both files.

This function will be called by the main function.


9. Write a function named findMinimum that accepts an array of integers and the size of the array as parameters. This function computes the minimum out of the test scores and returns the score.

• If a student has taken less then 5 tests, the minimum score is 0.

• If a student has taken all 5 tests, the minimum score is the minimum of the 5 scores in the array.

• This function will be called by the exportResults function.


10. Now that you’ve written and tested your program, make the following changes.

• Create a file named euidProject2_main.cpp and copy the main function to this file.

• Create a file named euidProject2_func.cpp and copy all the functions (other than the

main function) to this file.

• Create a file named euidProject2_header.cpp and copy all the global parameters, include

fields and function headers to the header file. Make sure you include the header file in

the .cpp files.

• You need to submit these three files to Canvas, where euid should be replaced by your

EUID.

• Compile the files together (including getNumber.cpp) and make sure it works correctly.


11. You must follow all the good programming practices of file I/O as well as dynamic memory programming throughout your code.


12. Your program must have exactly these listed functions. If you miss a function, you won’t get points for that. If write an extra function, you won’t get points for that either. The functions are:

• getNumber

• findMinimum

• add_Student

• remove_Student • display

• search

• exportResults

• main


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
C++ Programming
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did...

    c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did the program Except this time we modularize our program by writing functions, instead of writing the entire code in main. The program must have the following functions (names and purposes given below). Fot o tentoutefill datere nedefremfite You will have to decide as to what arguments must be passed to the functions and whether such passing must be by value or by reference or...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • I need help with this question for programming. The language we use is C++ The program...

    I need help with this question for programming. The language we use is C++ The program should ask the user if they want to search for a boy or girl name. It should then ask for the name search the appropriate array for the name and display a message saying what ranking that name received, if any. The name files (BoyNames.txt and GirlNames.txt) are in order from most popular to least popular and each file contains two hundred names. The...

  • c++ The program will be recieved from the user as input name of an input file...

    c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the...

  • have to create five different functions above and call it in the main fucntion. Project Exam...

    have to create five different functions above and call it in the main fucntion. Project Exam Statistics A CIS 22A class has two midterm exams with a score between 0 and 100 each. Fractional scores, such as 88.3 are not allowed. The students' ids and midterm exam scores are stored in a text file as shown below // id exam1 exam2 DH232 89 92 Write a program that reads data from an input file named exams.txt, calculates the average of...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • Write a c++ program which uses a structure having the indicated member names to store the...

    Write a c++ program which uses a structure having the indicated member names to store the following data: Name (student name) IDnum (student ID number) Tests (an array of three test scores) Average (average test score) Grade (course grade) The program will keep a list of three test scores for one student. The program may prompt the user for the name, ID number, and test scores, or these may be assigned within the program. The average test score will be...

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