Question

This is my code for a final GPA calculator. For this assignment, I'm not supposed to...

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);
}

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

******************************************************************************************
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.

Add a comment
Know the answer?
Add Answer to:
This is my code for a final GPA calculator. For this assignment, I'm not supposed to...
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
  • Professor Dolittle has asked some computer science students to write a program that will help him...

    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...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    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 (...

    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. ===========================================================...

  • Today assignment , find the errors in this code and fixed them. Please I need help...

    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...

  • 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>...

    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...

  • Trying to figure out how to complete my fourth case 4 (option exit), write a function...

    Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...

  • This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std;...

    This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...

  • C++. I need to alter this code below to the current specifications. Console Progressing Complete!!! Specifications...

    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...

  • I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

    I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink {    string name;    double cost;    int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() {    const int size = 5;       Drink drinks[size] = { {"Cola", 0.65, 2},    {"Root Beer", 0.70, 1},    {"Grape Soda", 0.75, 5},    {"Lemon-Lime", 0.85, 20},    {"Water", 0.90, 20} };    cout <<...

  • my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip>...

    my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip> #include<string> #include "bookdata.h" #include "bookinfo.h" #include "invmenu.h" #include "reports.h" #include "cashier.h" using namespace std; const int ARRAYNUM = 20; BookData bookdata[ARRAYNUM]; int main () { bool userChoice = false; while(userChoice == false) { int userInput = 0; bool trueFalse = false; cout << "\n" << setw(45) << "Serendipity Booksellers\n" << setw(39) << "Main Menu\n\n" << "1.Cashier Module\n" << "2.Inventory Database Module\n" << "3.Report Module\n"...

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