C++ Program for Managing Student Records, Exercises of Object Oriented Programming

The source code for a c++ program designed to manage student records. The program includes a student class with private attributes such as registration number, first and last names, semester, gpa, and cgpa. The program allows users to add, edit, and retrieve student records from a binary file. The document also includes functions for setting and getting student information.

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

netu
netu 🇮🇳

4.5

(4)

50 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <iostream>
#include <string.h>
#include <fstream>
#include <process.h>
#include <iomanip>
using namespace std;
class cStudent
{
private:
int registration;
char first_name[50];
char last_name[50];
int semester;
double GPA;
double CGPA;
public:
cStudent():
registration(0), GPA(0.0), CGPA(0.0), semester(1)
{
strcpy(first_name, "");
strcpy(last_name, "");
}
void set_student(int reg, char* fn, char* ln,
double gp, double cgp, int sem)
{
semester = sem;
registration = reg;
strcpy(first_name, fn);
strcpy(last_name, ln);
GPA = gp;
CGPA = cgp;
}
void update_fname(char* fn)
{
strcpy(first_name, fn);
}
void update_lname(char* ln)
{
strcpy(last_name, ln);
}
void update_gpa(double gp)
{
GPA = gp;
}
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download C++ Program for Managing Student Records and more Exercises Object Oriented Programming in PDF only on Docsity!

#include #include <string.h> #include #include <process.h> #include

using namespace std;

class cStudent { private: int registration; char first_name[50]; char last_name[50];

int semester; double GPA; double CGPA;

public: cStudent(): registration(0), GPA(0.0), CGPA(0.0), semester(1) { strcpy(first_name, ""); strcpy(last_name, ""); }

void set_student(int reg, char* fn, char* ln, double gp, double cgp, int sem) { semester = sem; registration = reg; strcpy(first_name, fn); strcpy(last_name, ln); GPA = gp; CGPA = cgp; }

void update_fname(char* fn) { strcpy(first_name, fn); }

void update_lname(char* ln) { strcpy(last_name, ln); }

void update_gpa(double gp) { GPA = gp; }

void update_cgpa(double cgp) { CGPA = cgp; }

void update_sem(int sem) { semester = sem; }

int get_reg() { return registration; }

char* get_first() { return first_name; }

char* get_last() { return last_name; }

double get_gpa() { return GPA; }

double get_cgpa() { return CGPA; }

int get_sem() { return semester; }

};

/* void main() { int reg; char fn[50]; char ln[50]; int sem; double gp; double cgp;

char option = 'y';

//a student object cStudent student;

//open the student record file for writing ofstream file("StudentRecord.bin", ios::binary | ios::out);

if(!file) { cout<<"Error opening the file!"; exit(0);

void main() { int reg;

char ed_opt; char ex_opt;

//a student object cStudent student;

//open the student record file for reading and writing fstream file("StudentRecord.bin", ios::binary | ios::out | ios::in);

if(!file) { cout<<"Error opening the file!"; exit(0); }

cout<<"-----Student Records-----"<<endl;

while(1) { cout<<"Enter Student Registration"<<endl; cin>>reg;

file.seekg((reg - 1) * sizeof(cStudent)); file.read(reinterpret_cast<char*> (&student), sizeof(cStudent));

cout<<setw(12)<<"Registration"<<setw(12)<<"First Name"<<setw(12) <<"Last Name"<<setw(10)<<"Semester"<<setw(5)<<"GPA"<<setw(5) <<"CGPA"<<endl;

cout<<setw(12)<<student.get_reg()<<setw(12)<<student.get_first()

<<setw(12)<<student.get_last()<<setw(10)<<student.get_sem()

<<setw(5)<<student.get_gpa()<<setw(5)<<student.get_cgpa()<<endl;

cout<<"Edit the Record (y/n) ?"<<endl; cin>>ed_opt;

if(ed_opt == 'y') { edit_student(student);

file.seekp((reg - 1) * sizeof(cStudent)); file.write(reinterpret_cast<const char*> (&student), sizeof(cStudent)); }

cout<<"Retrieve another Record (y/n) ?"<<endl; cin>>ex_opt;

if(ex_opt == 'n') break; }

file.close(); }

void edit_student(cStudent& student) { int option = 0;

char fn[50]; char ln[50]; int sem; double gp; double cgp;

cout<<setw(30)<<"Enter the following options"<<endl; cout<<setw(30)<<"Edit First Name? (1)"<<endl; cout<<setw(30)<<"Edit Last Name? (2)"<<endl; cout<<setw(30)<<"Edit GPA? (3)"<<endl; cout<<setw(30)<<"Edit CGPA? (4)"<<endl; cout<<setw(30)<<"Edit Semester? (5)"<<endl;

cin>>option;

switch (option) { case 1: cout<<"Enter First Name"<<endl; cin>>fn; student.update_fname(fn); break;

case 2: cout<<"Enter Last Name"<<endl; cin>>ln; student.update_lname(ln); break;

case 3: cout<<"Enter GPA"<<endl; cin>>gp; student.update_gpa(gp); break;