This is my code for a final GPA calculator. For this assignment, I'm not supposed to use global variables.
My question is: does my code contain a global variable/ global function, and if so how can I re-write it to not contain one?
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Title: Final GPA Calculator
* Course Computational Problem Solving CPET-121
* Developer: Elliot Tindall
* Date: Feb 3, 2020
* Description: This code takes grades that are input by the student
and displays
* their final average based on those grades
*/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include<iomanip>
#include <iostream>
using namespace std;
double average(double a[], int n)
{
// Find sum of array element
double sum = 0;
for (int i=0; i<n; i++)
sum += a[i];
return sum/n;
}
double round(double var)
{
// 37.66666 * 100 =3766.66
// 3766.66 + .5 =3767.16 for rounding off value
// then type cast to int so value is 3767
// then divided by 100 so the value converted into 37.67
double value = (int)(var * 100 + .5);
return (double)value / 100;
}
int main()
{
double homeworkAssignments[8];
double laboratoryAssignments[4];
double midTerm;
double finalExam;
char termPaperGrade;
bool classParticipation;
const double HwAssignWeightage = 15,LabAssignWeightage
=20,midTermWeightage =25,finalExamWeightage
=25,termPaperGradeWeightage =10,classParticipationWeightage=
5;
for(int i = 0;i<8;i++)
{
cout<<"Enter homework assignment "<<i+1<<" points
(out of 10):";
cin>>homeworkAssignments[i];
}
for(int i = 0;i<4;i++)
{
cout<<"Enter laboratory assignment "<<i+1<<"
points (out of 50):";
cin>>laboratoryAssignments[i];
}
cout<<"Enter mid term points (out of 100):";
cin>>midTerm;
cout<<"Enter final exam points (out of 100):";
cin>>finalExam;
cout<<"Enter term paper letter grade:";
cin>>termPaperGrade;
cout<<"Enter class participation( 0 or 1):";
cin>>classParticipation;
double averageHwAssignments =
average(homeworkAssignments,8)*10;
double averageLabAssignments =
(average(laboratoryAssignments,4)/50)*100;
double finalExamAverage = (finalExam/100)*100;
double midTermAverage = (midTerm/100)*100;
double termPaperGradeAverage;
switch(termPaperGrade)
{
case 'A':
case 'a':
termPaperGradeAverage=95;
break;
case 'B':
case 'b':
termPaperGradeAverage=85;
break;
case 'C':
case 'c':
termPaperGradeAverage=75;
break;
case 'D':
case 'd':
termPaperGradeAverage=65;
break;
case 'F':
case 'f':
termPaperGradeAverage=55;
break;
default:
termPaperGradeAverage=0;
}
double classParticipationAverage = classParticipation*100;
double finalAverage =
(HwAssignWeightage/100)*averageHwAssignments +
(LabAssignWeightage/100)*averageLabAssignments +
(midTermWeightage/100)*midTermAverage +
(finalExamWeightage/100)*finalExamAverage +
(termPaperGradeWeightage/100)*termPaperGradeAverage +
(classParticipationWeightage/100)*classParticipationAverage;
cout<<"Homework Average...........
:"<<setw(15)<<round(averageHwAssignments)<<endl;
cout<<"Laboratory Average.........
:"<<setw(15)<<round(averageLabAssignments)<<endl;
cout<<"Midterm Exam...............
:"<<setw(15)<<round(midTermAverage)<<endl;
cout<<"Final Exam.................
:"<<setw(15)<<round(finalExamAverage)<<endl;
cout<<"Term Paper.................
:"<<setw(15)<<termPaperGradeAverage<<"["<<termPaperGrade<<"]"<<endl;
cout<<"Class Participation........
:"<<setw(15)<<classParticipationAverage<<endl<<endl;
cout<<"Final Average..............
:"<<setw(15)<<round(finalAverage)<<endl;
string LetterGrade;
if(finalAverage>=93){
LetterGrade = "A";
}
else if(finalAverage>=90 && finalAverage <=
92.9)
{
LetterGrade = "A-";
}
else if(finalAverage>=87 && finalAverage <=
89.9)
{
LetterGrade = "B+";
}
else if(finalAverage>=83 && finalAverage <=
86.9)
{
LetterGrade = "B";
}else if(finalAverage>=80 && finalAverage <=
82.9)
{
LetterGrade = "B-";
}else if(finalAverage>=77 && finalAverage <=
79.9)
{
LetterGrade = "C+";
}else if(finalAverage>=73 && finalAverage <=
76.9)
{
LetterGrade = "C";
}else if(finalAverage>=70 && finalAverage <=
72.9)
{
LetterGrade = "C-";
}else if(finalAverage>=60 && finalAverage <=
69.9)
{
LetterGrade = "D";
}else{
LetterGrade = "F";
}
cout<<"Course Letter Grade........
:"<<setw(15)<<LetterGrade<<endl;
if(LetterGrade=="C-"||LetterGrade=="D"){
cout<<"Please see your Academic Advisor";
}
else if(LetterGrade=="F"){
cout<<"Sorry You need to repeat the course";
}
return(0);
}
******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As per HomeworkLib expert answering guidelines,Experts are supposed to
answer only certain number of questions/sub-parts in a post.Please
raise the remaining as a new question as per HomeworkLib
guidelines.
******************************************************************************************
A global variable is the one way that is declared outside of the main method and not inside any other method. IT is clear that you haven't used any global variables in your code.
This is my code for a final GPA calculator. For this assignment, I'm not supposed to...
(C++) I need to alter the code below to fit the given requirements. You will need to move the calculations to a function. A second function to return the Letter Grade. You will need to define a namespace to contain the CONST. Also, need to define an enum for letter grades: A, B, C, D, and F. Console Student Grade Calculation Form First Name: Larry Last Name: Hobbs Homework Average: 65 Midterm Grade: 90 Final Exam Grade: 75 Student: Larry...
Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...
I am working on this switch program everything seems to be ok but the compiler is giving me an error on the final closing brace and wanted to know where I am making an error #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int choice; char repeat; double MidTerm = 0; double FinalExam = 0; double Quiz1 = 0; double Quiz2 = 0; double MidTermGrade = 1, FinalExamGrade = 2, Quiz1Grade = 3, Quiz2Grade = 4,...
C++. I need to alter this code below to the current specifications. Console Progressing Complete!!! Specifications Included is an input file. Included is a function to aide, if needed Use the functions, enum, and namespace defined in Assignment 6. You will need to use a loop to read each student’s data You will need to load every homework grade into an array Calculate the homework average The homework average can be calculated while the array is loaded Move the printing...
Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them. #include <iostream> #include <cstring> #include <iomanip> using namespace std; const int MAX_CHAR = 100; const int MIN_A = 90; const int MIN_B = 80; const int MIN_C = 70; double getAvg(); char determineGrade(double); void printMsg(char grade); int main() { double score; char grade; char msg[MAX_CHAR]; strcpy(msg, "Excellent!"); strcpy(msg, "Good job!"); strcpy(msg, "You've passed!"); strcpy(msg, "Need...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
1. in this programe i want add some products to be shown after choosing choise ( show all products ) before i add any products. let say 10 products have added to the program then when the user choose (show all products ) all the 10 products appear and the user going to choose one and that one must has its own name, price,and quantity after that the quantity will be reduce. 2. allow the user to buy products. ===========================================================...
Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score average and Letter grade. No scores less than 0 or greater than 100 should be accepted #include<iostream> #include<string> using namespace std; int main() { double average[5]; string name[5]; char grade[5]; for(int i=0; i<=5; i++) { cout<<"Enter student name: "; cin.ignore(); getline(cin,name[i]); int sum=0; for(int j=0; j<5; j++) { int grades; cout<<"Enter Grades:"<<j+1<<" : "; cin>>grades; sum+=grades; } average[i]=(float)sum/5; if(average[i]>=90 && average[i]<=100) grade[i]='A'; else if(average[i]>=80...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
This is a C++ assignment that I'm trying to create and would like some help understanding while loops, with possible integration of for loops and if statements. This program only uses while, for, and if. I have some code that I have started, but where to go from there is what's giving me some trouble. This is involves a sentinel controlled while loop, and there are a lot of specifications below that I must have in the program. The program...