In this lab, you will build a small student records program using strings, structures, arrays of structures, and search functions.
The program stores student records that include an ID, name, and score. You will complete functions that print records, calculate class statistics, search by student ID, and validate record data.
By completing this lab, you will practice:
- Using
std::string - Comparing strings
- Accessing string characters
- Defining and using
structtypes - Accessing structure members with the dot operator
- Creating arrays of structures
- Passing structures and arrays of structures to functions
- Searching records by a string field
- Running automated tests with
make test
Your program must:
- Use a
Studentstructure - Store multiple students in an array of structures
- Print one student record
- Print all student records
- Calculate the class average score
- Find the highest score
- Search for a student by ID
- Validate student IDs
- Validate score values
- Pass the automated tests
You should primarily edit:
src/student_records.cppsrc/main.cpp
Do not edit the files in tests/ unless your instructor tells you to.
make
./mainmake testmake cleanstruct Student {
std::string id;
std::string name;
double score;
};bool isValidStudentId(std::string id);
bool isValidScore(double score);
void printStudent(const Student& student);
void printStudents(const Student students[], int size);
double calculateAverageScore(const Student students[], int size);
double findHighestScore(const Student students[], int size);
int findStudentById(const Student students[], int size, std::string targetId);
char determineLetterGrade(double score);Student Records
All students:
A123 Alex 91.5 A
B456 Maya 84 B
C789 Jordan 76.5 C
Class average: 84
Highest score: 91.5
Enter student ID to search for: B456
Found: B456 Maya 84 B
The tests call your functions directly. Your program may appear to run, but you will not receive full credit unless the required functions return correct values.
This lab focuses on strings and structures. Make sure your search function compares student IDs using std::string equality.