Question

COSC 1436 Programming Assignment 2 Programming Assignment 2 Refactoring is the process of taking existing code...

COSC 1436 Programming Assignment 2 Programming Assignment 2 Refactoring is the process of taking existing code and improving its design without changing the functionality. In this programming assignment, you are going to take your code from Programming Assignment 1 and refactor it so that it uses functions. The program should still do the following:  Get the name of a student  Get the name of three assignments  Get the grade of three assignments as integers  Calculates the average of the three assignments as a double  Displays the name of the student with his/her average to one decimal place  Displays the names and grades of the assignments neatly as a table. However, you will now need to create 5 functions. You should write a function for each of the following:  Get the name of the student  Get the name of the three assignments  Get the grade of each of the three assignments  Get the average of the three assignments  Display the grade information to the student including the student’s name, average, and list of grades As you can see, you basically need a function for each task your program performs. You will have a total of 6 functions including main. The main function should do nothing but create needed variables to pass to the functions and then call the functions in the correct order to produce the desired output. Make sure you use good programming style. Comment every variable, calculation, and function. Use self-documenting names for variables and functions. You should be able to reuse most of your code that you wrote for Programming Assignment 1. You should use arrays for the assignment names and the assignment grades. The code will need to be moved into the appropriate function. Some minor changes may need to be made to account for passing data into the function and returning a value from the function. Name your file PA2_lastName_firstName.cpp, replacing lastName with your actual last name and firstName with your actual first name.

COSC 1436 Programming Assignment 2 Notice that the possible output for a sample run will look the same as it did for Programming Assignment 1: Enter student first and last name: Roy Biv

Enter the name of assignment 1: Homework 1 Enter the name of assignment 2: Programming Lab 1 Enter the name of assignment 3: Exam 1 Enter the grade for Homework 1: 95 Enter the grade for Programming Lab 1: 88 Enter the grade for Exam 1: 100 The average for Roy Biv is 94.3 Here are your grades: Homework 1: 95 Programming Lab 1: 88 Exam 1: 100 Thank you for playing.

Homework Answers

Answer #1

Code

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

#define NUM_ASSIGNMENTS 3
string getName();
void getAssignments(string []);
void getGrades(int [],string []);
void displayInfo(int [],string [],double,string);
double getAverage(int []);
int main()
{
   string name;
   string assignments[NUM_ASSIGNMENTS];
   int grades[NUM_ASSIGNMENTS];
   double avg;

   name=getName();
   getAssignments(assignments);
   getGrades(grades,assignments);
   avg=getAverage(grades);
   displayInfo(grades,assignments,avg,name);
}

string getName()
{
   string name;
   cout<<"Enter student first and last name: ";
   getline(cin,name);
   return name;
}
void getAssignments(string assi[])
{
   cout<<endl;
   for(int i=0;i<NUM_ASSIGNMENTS;i++)
   {
       cout<<"Enter the name of assignment "<<(i+1)<<" :";
       getline(cin,assi[i]);
   }
}
void getGrades(int grades[],string assi[])
{
   cout<<endl;
   for(int i=0;i<NUM_ASSIGNMENTS;i++)
   {
       cout<<"Enter the grade for "<<assi[i]<<" :";
       cin>>grades[i];  
   }
}
double getAverage(int grades[])
{
   double sum=0;
   for(int i=0;i<NUM_ASSIGNMENTS;i++)
       sum+=grades[i];
   return sum/NUM_ASSIGNMENTS;
}
void displayInfo(int grd[],string assi[],double avg,string name)
{
   cout<<endl;
   cout<<fixed<<setprecision(1);
   cout<<"The average for "<<name<<" is "<<avg<<endl;
   cout<<"\nHere are your grades:"<<endl;
   for(int i=0;i<NUM_ASSIGNMENTS;i++)
       cout<<assi[i]<<": "<<grd[i]<<endl;

   cout<<"\n\nThank you for playing."<<endl;
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Know the answer?
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
Similar Questions
I have the below homework problem for a python programming class, and i really need some...
I have the below homework problem for a python programming class, and i really need some help!! First, take a set of 6 grades from a user and average them. Provide the average to the user. You need to check to make sure the grades are within the normal range. If the grade is less than 0 or more than 100, issue a warning to the user. You don't need to take the grade again, just let the user know....
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
In Programming Exercise 13 (Chapter 8), you are asked to write a program to calculate students’...
In Programming Exercise 13 (Chapter 8), you are asked to write a program to calculate students’ average test scores and their grades. Improve this programming exercise by adding a function to sort students’ names so that students’ data is output into ascending order according to their name. *Need the answer in C++*
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept generic parameters and perform operation on them. Deliverables A listing of the fully commented, working source code of the Java program Test data for the code A screen shot of the application in execution Step 1 Create a new project. Name it "Assignment_2_1". Step 2 Build a solution. Write the Java source code necessary to build a solution for the problem below:You have just...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
we will be taking data in as a file. you cannot use the data values in...
we will be taking data in as a file. you cannot use the data values in your source file but you must read in everything into variables and use it from there. First we need to include <fstream> at the top of our file. We will need to create an input file stream to work and ifstream. ifstream is a datatype. Create a variable with the datatype being ifstream. Variable is drfine by using the member accessor operator to call...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT