0% found this document useful (0 votes)
5 views3 pages

Hassan

This document is a C++ program that manages a school exam database by allowing users to add student records and view all records. It defines a Student structure to store names and marks in three subjects, calculates the average, and saves the data to a file. The program provides a simple menu interface for user interaction.

Uploaded by

hr990403
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Hassan

This document is a C++ program that manages a school exam database by allowing users to add student records and view all records. It defines a Student structure to store names and marks in three subjects, calculates the average, and saves the data to a file. The program provides a simple menu interface for user interaction.

Uploaded by

hr990403
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

struct Student {

string name;

int math, english, science;

float average;

};

void addStudent() {

Student s;

cout << "Enter student name: ";

cin.ignore();

getline(cin, s.name);

cout << "Enter Math marks: ";

cin >> s.math;

cout << "Enter English marks: ";

cin >> s.english;

cout << "Enter Science marks: ";

cin >> s.science;

s.average = (s.math + s.english + s.science) / 3.0;


ofstream file("results.txt", ios::app);

file << s.name << "," << s.math << "," << s.english << "," << s.science << "," << s.average << endl;

file.close();

cout << "Student record added!\n";

void viewRecords() {

ifstream file("results.txt");

string line;

cout << "Name\tMath\tEnglish\tScience\tAverage\n";

while (getline(file, line)) {

replace(line.begin(), line.end(), ',', '\t');

cout << line << endl;

file.close();

int main() {

int choice;

do {

cout << "\n--- School Exam Database ---\n";

cout << "1. Add Student Record\n";

cout << "2. View All Records\n";


cout << "3. Exit\n";

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case 1: addStudent(); break;

case 2: viewRecords(); break;

case 3: cout << "Exiting...\n"; break;

default: cout << "Invalid choice.\n";

} while (choice != 3);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy