Assignment 1-A

C++ Basics Practice

Build a complete Student Grade Calculator that combines all Module 1 concepts: variables, data types, operators, input/output streams, and basic program structure. This project tests your understanding of fundamental C++ programming.

3-4 hours
Beginner
150 Points
Submit Assignment
What You'll Practice
  • Use all C++ data types correctly
  • Apply arithmetic and logical operators
  • Handle user input with cin
  • Format output with cout
  • Write clean, well-documented code
Contents
01

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.

Standard C++ Only: You must use ONLY standard C++ libraries (iostream, iomanip, string). No external libraries or platform-specific headers allowed. This tests your understanding of core C++.
Skills Applied: This assignment tests your understanding of C++ basics (Topic 1.1), environment setup (Topic 1.2), and your first program concepts (Topic 1.3) from Module 1.
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

Ready to submit? Already completed the assignment? Submit your work now!
Submit Now
02

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.

03

Requirements

Your grade_calculator.cpp must implement ALL of the following features. Each feature is mandatory and will be tested individually.

1
Program Header and Includes

Start your program with proper structure:

  • Include necessary headers: iostream, iomanip, string
  • Use using namespace std; or prefix with std::
  • 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;
2
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)
3
Variable Declarations

Declare appropriate variables using correct data types:

  • string for student name
  • int for student ID and individual subject marks
  • double for average and percentage calculations
  • char for letter grade
// Variable declarations
string studentName;
int studentId;
int math, science, english, history, programming;
double totalMarks, average, percentage;
char letterGrade;
4
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;
5
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
6
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';
}
7
Formatted Output

Display a formatted report card using iomanip:

  • Use setw() for column alignment
  • Use setprecision() for decimal places
  • Use fixed for 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;
8
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
9
Additional Statistics

Calculate and display:

  • Highest scoring subject
  • Lowest scoring subject
  • Difference between highest and lowest (range)
10
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
========================================
04

Submission

Create a public GitHub repository with the exact name shown below:

Required Repository Name
cpp-grade-calculator
github.com/<your-username>/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.)
Important: Before submitting, compile and run your program to make sure it works without errors and produces the expected output format!
Submit Your Assignment

Enter your GitHub username - we'll verify your repository automatically

05

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 Assignment
06

What 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

07

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
08

Pre-Submission Checklist

Code Requirements
Repository Requirements