0% found this document useful (0 votes)
19 views7 pages

School Manangement

Uploaded by

John
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)
19 views7 pages

School Manangement

Uploaded by

John
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/ 7

NAME:MWANGANGI JOHN KASINGA

REG. NO:ED201/112855/23
SCHOOL:B.ED.
PROGRAM:PHYSICS/COMPUTER
TITLE: OOP 1

#include<iostream>
#include<string>
#include<cstring>
#include<cctype>

class Student {
private:
int title; // Master = 1, Mr = 2, Miss = 3
std::string studentName;
int rollNo;
std::string fatherName;
std::string motherName;
std::string address;
std::string bloodGroup;

public:
void getDetails(); // Get Student Details from the user
void printDetails(); // Print the details of the Student
};

void Student::getDetails() {
std::cout << "Enter Title (Master = 1, Mr = 2, Miss = 3): ";
do {
std::cin >> title;
} while (title != 1 && title != 2 && title != 3);

std::cin.ignore();

std::cout << "Enter Student Name: ";


std::getline(std::cin, studentName);

std::cout << "Enter Roll No.: ";


do {
std::cin >> rollNo;
} while (rollNo < 1);

std::cin.ignore();

std::cout << "Enter Father's Name: ";


std::getline(std::cin, fatherName);
std::cout << "Enter Mother's Name: ";
std::getline(std::cin, motherName);

std::cout << "Enter Address: ";


std::getline(std::cin, address);

std::cout << "Enter Blood Group: ";


std::cin >> bloodGroup;
}
void Student::printDetails() {
std::cout << "Student Name : " << strTitle(title) << ' ' << studentName << std::endl;
std::cout << "Roll No. : " << rollNo << std::endl;
std::cout << "Father's Name : " << fatherName << std::endl;
std::cout << "Mother's Name : " << motherName << std::endl;
std::cout << "Address : " << address << std::endl;
std::cout << "Blood Group : " << bloodGroup << std::endl;

}
int retRollNo(){ //Return Roll No
return rollNo;
}
char * retString(char x){ //Return all strings available from the Student Class
if(x=='T')
return strTitle(title);
if(x=='N')
return studentName;
if(x=='F')
return fatherName;
if(x=='M')
return motherName;
if(x=='A')
return address;
if(x=='B')
return bloodGroup;

}
char * retStudentName(){ //Returns Student Name
return retString('N');
}
void modDetail(char ch); //Modify Details for Student
};

void Student::getDetails(){ //Get Student Details from user


system("CLS");
std::cout<<"Enter Title \n(Master = 1, Mr = 2, Miss = 3) : ";
do{
title = std::cin;
}while(title!=1 && title!=2 && title!=3);
std::cout<<"Enter Student Name : ";
do{
gets(studentName);
}while(strlen(studentName)==0);
std::cout<<"Enter Roll No. : ";
do{
rollNo=std::cin;
}while(rollNo<1);
std::cout<<"Enter Father Name : ";
do{
gets(fatherName);
}while(strlen(fatherName)==0);
std::cout<<"Enter Mother Name : ";
do{
gets(motherName);
}while(strlen(motherName)==0);
std::cout<<"Enter Address : ";
do{
gets(address);
}while(strlen(address)==0);
std::cout<<"Enter Blood Group : ";
int v = 0,i;
do{
gets(bloodGroup);
for (i=0;i<strlen(bloodGroup);i++) bloodGroup[i] = toupper(bloodGroup[i]);
for(i=0;i<8;i++)
if(!strcmp(bloodGroup,bGs[i])){
v=1;
break;
}
}while(!v);
}
void student::modDetail(char ch){ //Modify Details for Student
system ("CLS");
if(ch=='T'){ //Argument will tell which detail to
modify
'std::cout'<<"Enter Title \n(Master = 1, Mr = 2, Miss = 3) : ";
do{
'title'='scan'();
}while('title'!=1 && title!=2 && title!=3);
}
else if(ch=='N'){
'std::cout'<<"Enter Student Name : ";
do{
'gets'('studentName');
}while('strlen'('studentName')==0);
}
else if(ch=='R'){
int r='rollNo'; //Save current Roll No.
'std::cout'<<"Enter Roll No. : ";
'fstream' fl(FLBSTUD,ios::in|ios::binary);
student obj;
do{
rollNo = 'scan'();
'fl'.close();
fl.open('FLBSTUD','ios'::in|'ios'::binary);
while(!fl.eof()){
fl.read((char*)&'obj', sizeof(obj));
if(fl.eof())
break;
if(obj.retRollNo()==rollNo && r!=rollNo){ //Check if the new
rollNo already exists
std::cout<<"\nSame Roll No. Already Exists !\n";
std::cout<<"Enter Roll No. : ";
rollNo = -1;
}
}
{while(rollNo<1);
fl.close();
}
if else(ch=='F'){
std::cout<<"Enter Father Name : ";
do{
'gets'('fatherName');
}while('strlen'(fatherName)==0);
}
else if(ch=='M'){
std::cout<<"Enter Mother Name : ";
do{
'gets'('motherName');
}while('strlen'('motherName')==0);
}
else if(ch=='A'){
std::cout<<"Enter Address : ";
do{
'gets'('address');
}while('strlen'('address')==0);
}
else {
std::cout<<"Enter Blood Group : ";
int v = 0,i;
do{
'gets'('bloodGroup'); //Loop for
checking valid Blood Groups
for (i=0;i<'strlen'(bloodGroup);i++) bloodGroup[i] =
'toupper'(bloodGroup[i]);
for(i=0;i<8;i++)
if(!'strcmp'(bloodGroup,'bGs'[i])){
v=1;
break;
}
}while(!v);
}
}
while (class Class { //Class class for storing
Records in class file
int class_standard;
char studentName[30];
int rollNo;
char Subject[30];
public:
void getDetails(); //Get Class Record Detail from user
void printDetails(int i=1){ //Print Class Record Details

std::cout<<"Student Name : "<<studentName<<endl;


if(i)
std::cout<<"Class Standard : "<<class_standard<<endl;
std::cout<<"Roll No. : "<<rollNo<<endl;
std::cout<<"Subject : "<<Subject<<endl;
}
int retClass(){ //Return Class Standard
return class_standard;
}
int retRollNo(){ //Return Roll No
return rollNo;
}
char * retString(char x){ //Return all strings avaialable from the Class class
if(x=='N')
return studentName;
if(x=='S')
return Subject;
}
char * retStudentName(){ //Return Student Name
return retString('N');
}
void modDetail(char ch);
};
void Class::getDetails(){ //Get Class Record Details from user
system("CLS");
std::cout<<"Enter Class Standard : ";
do{
class_standard = std::cin;
}while(class_standard>12 || class_standard<1);
std::cout<<"Enter Student Name : ";
do{
gets(studentName);
}while(strlen(studentName)==0);
std::cout<<"Enter Roll No. : ";
do{
rollNo = std::cin;
}while(rollNo<1);
std::cout<<"Enter Subject : ";
do{
gets(Subject);
}while(strlen(Subject)==0);
}
void Class::modDetail(char ch){ //Modify Class Record
system("CLS");
if(ch=='C'){
std::cout<<"Enter Class Standard : ";
do{
class_standard = std::cin;
}while(class_standard>12 || class_standard<1);
}
else if(ch=='N'){
std::cout<<"Enter Student Name : ";
do{
gets(studentName);
}while(strlen(studentName)==0);
}
else if(ch=='R'){
fstream fl(FLBCLAS,ios::in|ios::binary);
Class obj;
int r = rollNo; //Save Current Roll No.
std::cout<<"Enter Roll No. : ";
do{
rollNo = std::cin;
fl.close();
fl.open(FLBCLAS,ios::in|ios::binary);
while(!fl.eof()){
fl.read((char*)&obj, sizeof(obj));
if(fl.eof())
break; //Check if new Roll
No. Already Exists
if(obj.retRollNo()==rollNo && r!=rollNo){
std::cout<<"\nSame Roll No. Already Exists !\n";
std::cout<<"Enter Roll No. : ";
rollNo=-1;
}
}
}while(rollNo<1);
fl.close();
}
else {
std::cout<<"Subject : ";
int v = 0,i;
do{
gets(Subject);
}while(strlen(Subject)==0);
}
}
void insertStudent(){ //Insert Student Record in File
system("CLS");
Student obj,obj2;
char ch;
int v=0;
std::cout<<"Enter Details for new Student :\n";
obj.getDetails();
fstream fl1(FLBSTUD, ios::in|ios::binary);
ofstream fl2;
if(!fl1){ //If file does not exist, create new file
fl2.open(FLBSTUD,ios::out|ios::binary);
fl2.write((char*)&obj, sizeof(obj));
fl2.close();
std::cout<<"Record successfully inserted !\n";
return;
}
while(!fl1.eof()){
fl1.read((char*)&obj2,sizeof(obj));
if(fl1.eof()){
break;
}
if(obj.retRollNo()==obj2.retRollNo()){ //If record with same Roll No.
exists, then abort insertion
std::cout<<"Record with same Roll No. with following details already
exists : \n";
obj2.printDetails();
std::cout<<"Insertion Aborted !\n";
return;
}
else if(strcmpi(obj.retStudentName(),obj2.retStudentName())==0){
if (!v) //Warns user
that Record with same name exists
std::cout<<"Warning : Record with same name exists with follwing
details : \n";
obj2.printDetails();
std::cout<<'\n';
v=1;
}
}
if(v){
std::cout<<"Do you still wish to insert record (Y/N) ? ";
do{
//Asks for user confirmation after warning
std::cin>>ch;
ch = toupper(ch);
}while(ch!= 'Y' && ch!='N');
if(ch=='N'){
std::cout<<"Insertion Aborted !\n";
Return 0;

1. Class Student:
- The Student class is defined with private member variables to store information about a student
such as title, student name, roll number, father's name, mother's name, address, and blood group.
- The class includes public member functions to get student details (getDetails), print student details
(printDetails), return roll number (retRollNo), return a string based on input character (retString),
return student name (retStudentName), and modify details based on input character (modDetail).

2. getDetails() :
- This function prompts the user to input various details of the student such as title, name, roll
number, father's name, mother's name, address, and blood group.

3. printDetails() :
- This function prints out the details of the student in a formatted manner by using the retString
function to convert the title integer to a string representation.

4. retRollNo() :
- This function returns the roll number of the student.

5. retString(char x) :
- This function returns a string based on the input character x, where different characters represent
different fields of student information (e.g., 'T' for title, 'N' for name, 'F' for father's name, etc.).

6. retStudentName() :
- This function returns the student's name by calling retString with the character 'N'.

7. modDetail(char ch) :
- This function is declared but not implemented in the provided code. It is intended to modify
specific details of the student based on the input character ch.

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