Assignment Overview
In this assignment, you will build a complete Student Grade Calculator system. This comprehensive project requires you to apply ALL concepts from Module 1: variables, data types, operators, constants, input/output streams, and proper program structure with comments.
iostream, iomanip, string).
No external libraries or platform-specific headers allowed. This tests your understanding of core C++.
Intro to C++ (1.1)
History, features, compilation process, program structure
Environment Setup (1.2)
Compiler, IDE, compiling and running programs
First Program (1.3)
Variables, data types, cin/cout, operators, formatting
The Scenario
TechAcademy Grade System
You have been hired as a Junior C++ Developer at TechAcademy, an educational institution that needs a student grade calculator. The academic coordinator has given you this task:
"We need a C++ program that can calculate student grades. It should take marks for different subjects, calculate the average, determine the letter grade, and display a formatted report card. Can you build this for us?"
Your Task
Create a C++ file called grade_calculator.cpp that implements a complete
grade calculation system. Your code must handle user input, perform calculations,
and display formatted output using all concepts taught in Module 1.
Requirements
Your grade_calculator.cpp must implement ALL of the following features.
Each feature is mandatory and will be tested individually.
Program Header and Includes
Start your program with proper structure:
- Include necessary headers:
iostream,iomanip,string - Use
using namespace std;or prefix withstd:: - Add a comment header with your name, date, and program description
/*
* Student Grade Calculator
* Author: [Your Name]
* Date: [Submission Date]
* Description: A program to calculate and display student grades
*/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
Constants Declaration
Define constants for your program:
- Maximum marks per subject (use
const int MAX_MARKS = 100;) - Number of subjects (use
const int NUM_SUBJECTS = 5;) - Grade thresholds (A: 90+, B: 80-89, C: 70-79, D: 60-69, F: below 60)
Variable Declarations
Declare appropriate variables using correct data types:
stringfor student nameintfor student ID and individual subject marksdoublefor average and percentage calculationscharfor letter grade
// Variable declarations
string studentName;
int studentId;
int math, science, english, history, programming;
double totalMarks, average, percentage;
char letterGrade;
User Input
Get input from the user for:
- Student name (use
getline()for names with spaces) - Student ID number
- Marks for 5 subjects: Mathematics, Science, English, History, Programming
- Include input prompts that are clear and user-friendly
cout << "Enter student name: ";
getline(cin, studentName);
cout << "Enter student ID: ";
cin >> studentId;
cout << "Enter marks for Mathematics (0-100): ";
cin >> math;
Calculations
Perform the following calculations:
- Total marks = sum of all 5 subjects
- Maximum possible marks = NUM_SUBJECTS × MAX_MARKS
- Percentage = (totalMarks / maxPossible) × 100
- Average = totalMarks / NUM_SUBJECTS
- Determine letter grade based on percentage
Grade Determination
Use conditional statements to determine the letter grade:
- A: 90% and above (Excellent)
- B: 80-89% (Good)
- C: 70-79% (Average)
- D: 60-69% (Below Average)
- F: Below 60% (Fail)
// Grade determination using if-else
if (percentage >= 90) {
letterGrade = 'A';
} else if (percentage >= 80) {
letterGrade = 'B';
} else if (percentage >= 70) {
letterGrade = 'C';
} else if (percentage >= 60) {
letterGrade = 'D';
} else {
letterGrade = 'F';
}
Formatted Output
Display a formatted report card using iomanip:
- Use
setw()for column alignment - Use
setprecision()for decimal places - Use
fixedfor consistent decimal display - Include decorative borders using characters
cout << fixed << setprecision(2);
cout << "\n========================================\n";
cout << " STUDENT REPORT CARD \n";
cout << "========================================\n";
cout << "Student Name: " << studentName << endl;
cout << "Student ID: " << studentId << endl;
cout << "----------------------------------------\n";
cout << setw(15) << left << "Subject"
<< setw(10) << right << "Marks" << endl;
Pass/Fail Status
Add logic to determine and display pass/fail status:
- A student passes if all subjects have marks >= 40
- Use logical operators (
&&) to check all conditions - Display appropriate message based on status
Additional Statistics
Calculate and display:
- Highest scoring subject
- Lowest scoring subject
- Difference between highest and lowest (range)
Code Quality
Ensure your code meets quality standards:
- Proper indentation (consistent spacing)
- Meaningful variable names
- Comments explaining each section
- No magic numbers (use constants)
- Clean, readable code structure
Expected Output Example
========================================
STUDENT REPORT CARD
========================================
Student Name: John Smith
Student ID: 12345
----------------------------------------
Subject Marks
----------------------------------------
Mathematics 85
Science 92
English 78
History 88
Programming 95
----------------------------------------
Total Marks: 438 / 500
Percentage: 87.60%
Average: 87.60
Letter Grade: B
Status: PASSED
----------------------------------------
Highest Subject: Programming (95)
Lowest Subject: English (78)
Range: 17
========================================
Submission
Create a public GitHub repository with the exact name shown below:
Required Repository Name
cpp-grade-calculator
Required Files
cpp-grade-calculator/
├── grade_calculator.cpp # Your main C++ source file
├── sample_output.txt # Sample output from running your program
└── README.md # REQUIRED - see contents below
README.md Must Include:
- Your full name and submission date
- Brief description of your program
- Instructions to compile and run (e.g.,
g++ -o grade grade_calculator.cpp) - Any challenges faced and how you solved them
Do Include
- All 10 requirements implemented
- Comments explaining your code
- Properly formatted output
- Sample output file
- Use of constants (no magic numbers)
- README.md with all required sections
Do Not Include
- Executable files (.exe, .out)
- IDE-specific files (.vs, .idea folders)
- Code that doesn't compile
- Hardcoded calculations
- Platform-specific headers (windows.h, etc.)
Enter your GitHub username - we'll verify your repository automatically
Grading Rubric
Your assignment will be graded on the following criteria:
| Criteria | Points | Description |
|---|---|---|
| Program Structure | 20 | Proper includes, namespace usage, main function structure, and header comments |
| Variables & Data Types | 25 | Correct use of int, double, string, char, and const for appropriate purposes |
| Input/Output | 30 | Proper use of cin, cout, getline(), and iomanip for formatting |
| Calculations | 25 | Correct arithmetic operations, grade determination logic, and statistics |
| Operators | 15 | Correct use of arithmetic, relational, and logical operators |
| Code Quality | 35 | Comments, naming conventions, indentation, and clean organization |
| Total | 150 |
Ready to Submit?
Make sure you have completed all requirements and reviewed the grading rubric above.
Submit Your AssignmentWhat You Will Practice
Variables & Data Types (1.3)
Working with int, double, string, char, and understanding when to use each type
Input/Output Streams
Using cin, cout, getline() for user interaction and iomanip for formatted output
Operators
Arithmetic (+, -, *, /), relational (>, <, >=, <=, ==), and logical (&&, ||) operators
Program Structure
Writing clean, well-organized code with proper comments and documentation
Pro Tips
C++ Best Practices
- Use meaningful variable names (avoid x, y, z)
- Initialize variables when declaring them
- Use const for values that don't change
- Add comments for complex logic
Input Handling
- Use getline() after cin >> to handle strings
- Clear input buffer with cin.ignore() if needed
- Provide clear prompts for user input
- Consider input validation (bonus)
Time Management
- Start with basic input/output first
- Add calculations step by step
- Test frequently as you build
- Save formatting for last
Common Mistakes
- Forgetting to use fixed with setprecision
- Integer division instead of double
- Missing semicolons
- Using = instead of == in conditions