Skip to content
C project #04Beginner

Class Grade Report

Enter a class's marks and get a formatted report with totals, percentages, grades, subject toppers and a grade histogram.

Estimated time
~3 hours to build
Files
5 files · 302 lines
Technologies
C11, <stdio.h>, <string.h>

Introduction

Teachers produce mark sheets every semester; this project automates one. It is a natural exercise in arrays — a 2D array holds every mark — and in producing clean, aligned output.

Problem statement

Read the number of students and subjects, each subject's name, and each student's name and marks. Print a report table with each student's marks, total, percentage and grade, followed by the class average, the topper in each subject and a text histogram of the grade distribution. Reject invalid marks.

Objectives

  • Store tabular data in two-dimensional arrays
  • Compute per-row and per-column statistics
  • Map percentages to grades with an if-else ladder
  • Format a professional-looking report

Features

  • Up to 60 students and 6 subjects
  • Totals, percentages and grades (O, A, B, C, P, F)
  • Class average and subject toppers
  • Grade distribution histogram

Concepts demonstrated

  • 2D arrays
  • Nested loops
  • if-else ladder
  • Formatted output

System architecture

Three global arrays hold the data: names, subjects and the 2D marks. Input is read in nested loops (students × subjects). Report generation is a second pass that prints each row and accumulates the class percentage and grade counts; a third pass scans each column for the topper.

Folder structure

TextProject tree
grade-report/
├── README.md
├── Makefile
├── src/main.c
├── tests/expected-output.txt
└── tests/sample-input.txt

Complete source code

Makefile

20 lines
MakefileMakefile
# Generated for KENHOLT Skills. Usage: make | make test | make clean
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -O2
SRC := $(wildcard src/*.c)
HDR := $(wildcard src/*.h)
ARGS := $(shell cat tests/args.txt 2>/dev/null)
INPUT := $(wildcard tests/sample-input.txt)
app: $(SRC) $(HDR)
$(CC) $(CFLAGS) -Isrc $(SRC) -o app -lm
test: app
./app $(ARGS) $(if $(INPUT),< $(INPUT),) > actual.txt
diff actual.txt tests/expected-output.txt && echo "Test passed: output matches tests/expected-output.txt"
clean:
rm -f app app.exe actual.txt
.PHONY: test clean

What each file does

src/main.c
Data arrays, grade_for, validated input via read_int, and the three-pass report in main.
Makefile
Build automation: make builds ./app, make test runs the sample session and compares it with the expected output, make clean removes build files.

How to run it

Build

Terminal
gcc -std=c11 -Wall -Wextra -Isrc src/*.c -o app -lm
# or simply: make

Run

Terminal
./app # Linux / macOS
.\app.exe # Windows

Test against the expected output

Terminal
./app < tests/sample-input.txt > actual.txt
diff actual.txt tests/expected-output.txt # no output means they match
# Windows PowerShell:
# Get-Content tests\sample-input.txt | .\app.exe > actual.txt
# Compare-Object (Get-Content actual.txt) (Get-Content tests\expected-output.txt)

Expected output

Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.

Texttests/expected-output.txt
Number of students:
Number of subjects:
Name of subject 1:
Name of subject 2:
Name of subject 3:
Student 1 name:
Maths mark (0-100):
Physics mark (0-100):
C mark (0-100):
Student 2 name:
Maths mark (0-100):
Physics mark (0-100):
C mark (0-100):
Student 3 name:
Maths mark (0-100):
Physics mark (0-100):
C mark (0-100):
Student 4 name:
Maths mark (0-100):
Physics mark (0-100):
C mark (0-100):
Name Maths Physics C Total % Grade
-----------------------------------------------------------
Asha 92 88 95 275 91.67 O
Ravi 67 72 58 197 65.67 C
Meera 81 79 90 250 83.33 A
Kiran 35 42 38 115 38.33 F
Class average: 69.75%
Subject toppers:
Maths Asha (92)
Physics Asha (88)
C Asha (95)
Grade distribution:
O: 1 #
A: 1 #
B: 0
C: 1 #
P: 0
F: 1 #
Input
4
3
Maths
Physics
C
Asha
92
88
95
Ravi
67
72
58
Meera
81
79
90
Kiran
35
42
38

Testing

  • Compare with tests/expected-output.txt (4 students, 3 subjects).
  • Enter a mark of 105 and confirm the program reports it as invalid.
  • Check by hand: Asha's 275/300 is 91.67%, grade O.

Common errors

Names longer than 23 characters are cut off

This is deliberate: %23s protects the 24-byte buffer. Increase NAME_LEN if you need longer names.

Garbage in the report

Make sure the number of students and subjects is read before the arrays are filled, and that every mark is read with %d.

Possible improvements

  • Save and load the class from a CSV file
  • Sort the report by percentage
  • Support different maximum marks per subject

Additional challenges

  1. 1Print the rank of every student, handling ties.
  2. 2Calculate each subject's average and standard deviation.
  3. 3Highlight students who failed any single subject even if their overall grade is a pass.

Built and tested it yourself? Mark it to update your dashboard.