Turbo C++ Menu Driven Student Mark List Preparation with persistant data
Here is Turbo C++ source code Menu Driven Student Mark List Preparation with persistant data. You can add student name and marks for 5 subjects. Then you will have an option to view, edit and delete the student and marks information.
All the data you entered would be saved into a file. so that if you are re running the program, then you do not have add any old data.
Related Links
Turbo C++ Menu Driven Student Mark List Preparation with persistant data
-
Visual C++ Menu Driven Student Mark List Preparation with persistant data
-
C# Menu Driven Student Mark List Preparation with persistant data
To get the simple version of student marklist with out menu and streaming
Source Code
// Student MarkList Preparation
//
#include <conio.h>
#include <process.h>
#include <dos.h>
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#pragma pack(2)
struct CStudent
{
public:
char name[64];
int marks[5];
int total;
};
struct CStudents
{
#define MaxSz 100
char m_fileName[1024];
int m_nMaxStudents;
CStudent m_studList[MaxSz];
CStudents(const char *filename);
void AddRecord(const char *name, int *marks);
void EditRecord(int pos, const char *name, int *marks);
void DeleteRecord(int pos);
int ReadRecords();
int WriteRecords();
};
CStudents::CStudents(const char *filename)
{
m_nMaxStudents = 0;
strcpy(m_fileName, filename);
}
void CStudents::AddRecord(const char *name, int *marks)
{
int pos = m_nMaxStudents;
strcpy(m_studList[pos].name,name);
m_studList[pos].total = 0;
for(int i = 0; i < 5; i++)
{
m_studList[pos].marks[i] = marks[i];
m_studList[pos].total += marks[i];;
}
m_nMaxStudents++;
WriteRecords();
}
void CStudents::EditRecord(int pos, const char *name, int *marks)
{
strcpy(m_studList[pos].name,name);
m_studList[pos].total = 0;
for(int i = 0; i < 5; i++)
{
m_studList[pos].marks[i] = marks[i];
m_studList[pos].total += marks[i];
}
WriteRecords();
}
void CStudents::DeleteRecord(int pos)
{
m_nMaxStudents--;
for(int i = pos; i < m_nMaxStudents; i++)
{
m_studList[i] = m_studList[i + 1];
}
WriteRecords();
}
int CStudents::ReadRecords()
{
FILE *istream = fopen(m_fileName, "rb");
if (istream == 0)
return 0;
char buf[4096];
int nTotalRecordsRead = 0;
for(int i = 0; i < MaxSz; i++)
{
if(feof(istream))
break;
int nBytesRead = fread(buf, 1, sizeof(CStudent), istream);
if(nBytesRead < sizeof(CStudent))
break;
char *p = (char*)(&m_studList[i]);
memcpy(p, buf, sizeof(CStudent));
nTotalRecordsRead++;
}
fclose(istream);
m_nMaxStudents = nTotalRecordsRead;
return nTotalRecordsRead;
}
int CStudents::WriteRecords()
{
FILE *ostream = fopen(m_fileName, "wb");
if (ostream == 0)
return 0;
int nTotalRecordsWritten = 0;
char buf[4096];
for(int i = 0; i < m_nMaxStudents; i++)
{
fwrite((char*)&m_studList[i], 1, sizeof(CStudent), ostream);
nTotalRecordsWritten++;
}
fclose(ostream);
return nTotalRecordsWritten;
}
CStudents theStudents("c:\\marklist.bin");
int DisplayMainMenu()
{
::system("cls");
gotoxy(10,4);
cout << "Welcome to Student MarkList Application";
gotoxy(10,5);
cout << "___________________________________________";
gotoxy(10,6);
cout << "1. Add Student Mark List";
gotoxy(10,7);
cout << "2. Edit Student Mark List";
gotoxy(10,8);
cout << "3. View Student Mark List";
gotoxy(10,9);
cout << "4. Delete Student Mark List";
gotoxy(10,10);
cout << "5. Exit";
gotoxy(10,11);
cout << "___________________________________________";
gotoxy(10,13);
cout << "Enter your Selection: ";
int m = -1;
cin >> m;
return m;
}
void ViewRecords()
{
theStudents.ReadRecords();
::system("cls");
gotoxy(10,4);
cout << "Welcome to Student Mark List Application";
gotoxy(10,5);
cout << "_______________________________________________________________";
gotoxy(10,6);
cout << "SNo Student Name Sub1 Sub2 Sub3 Sub4 Sub5 Total";
gotoxy(10,7);
cout << "_______________________________________________________________";
int pos = 8;
// Enable Paging
for(int i = 0; i < theStudents.m_nMaxStudents; i++)
{
gotoxy(10,pos);
cout << i + 1;
gotoxy(14,pos);
cout << theStudents.m_studList[i].name;
gotoxy(33,pos);
cout << theStudents.m_studList[i].marks[0];
gotoxy(40,pos);
cout << theStudents.m_studList[i].marks[1];
gotoxy(47,pos);
cout << theStudents.m_studList[i].marks[2];
gotoxy(54,pos);
cout << theStudents.m_studList[i].marks[3];
gotoxy(61,pos);
cout << theStudents.m_studList[i].marks[4];
gotoxy(68,pos);
cout << theStudents.m_studList[i].total;
pos++;
}
gotoxy(10,pos++);
cout << "_______________________________________________________________";
pos++;
gotoxy(10,pos++);
}
void InputRecords()
{
while(1)
{
::system("cls");
gotoxy(10,4);
cout << "Welcome to Student Mark List Application";
gotoxy(10,5);
cout << "__________________________________________________________";
gotoxy(10,6);
cout << "Student Name: ";
gotoxy(10,7);
cout << "Sub1 Mark: ";
gotoxy(10,8);
cout << "Sub2 Mark: ";
gotoxy(10,9);
cout << "Sub3 Mark: ";
gotoxy(10,10);
cout << "Sub4 Mark: ";
gotoxy(10,11);
cout << "Sub5 Mark: ";
gotoxy(10,12);
cout << "__________________________________________________________";
gotoxy(23,6);
char name[64];
cin >> name;
int marks[5];
for(int i = 0; i < 5; i++)
{
gotoxy(23,7 + i);
cin >> marks[i];
}
theStudents.AddRecord(name, marks);
gotoxy(10,14);
cout << "Do you want to add another record (Y/N)? ";
char ch = getch();
if(ch == 'Y' || ch == 'y')
continue;
else
break;
}
}
void EditRecords()
{
ViewRecords();
cout << "Enter the serial number you want to edit: ";
int m;
cin >> m;
if(m >= 1 && m <= theStudents.m_nMaxStudents)
{
::system("cls");
gotoxy(10,4);
cout << "Welcome to Student Mark List Application";
gotoxy(10,5);
cout << "__________________________________________________________";
gotoxy(10,6);
cout << "Student Name: ";
gotoxy(10,7);
cout << "Sub1 Mark: ";
gotoxy(10,8);
cout << "Sub2 Mark: ";
gotoxy(10,9);
cout << "Sub3 Mark: ";
gotoxy(10,10);
cout << "Sub4 Mark: ";
gotoxy(10,11);
cout << "Sub5 Mark: ";
gotoxy(10,12);
cout << "__________________________________________________________";
gotoxy(23,6);
char name[64];
cin >> name;
int marks[5];
for(int i = 0; i < 5; i++)
{
gotoxy(23,7 + i);
cin >> marks[i];
}
theStudents.EditRecord(m - 1, name, marks);
gotoxy(10,12);
cout << "Record updated. Press any key to return to Main Menu";
getch();
}
else
{
gotoxy(10,12);
cout << "Invalid Entry. Press any key to return to Main Menu";
getch();
}
}
void DeleteRecords()
{
ViewRecords();
cout << "Enter the serial number you want to delete: ";
int m;
cin >> m;
if(m >= 1 && m <= theStudents.m_nMaxStudents)
{
theStudents.DeleteRecord(m - 1);
cout << "Record deleted. Press any key to return to Main Menu";
getch();
}
else
{
cout << "Invalid Entry. Press any key to return to Main Menu";
getch();
}
}
int main()
{
theStudents.ReadRecords();
while(1)
{
int selection = DisplayMainMenu();
switch(selection)
{
case 1:
InputRecords();
break;
case 2:
EditRecords();
break;
case 3:
{
ViewRecords();
cout << "Press any key to return to Main Manu: ";
getch();
}
break;
case 4:
DeleteRecords();
break;
case 5:
default:
return 0;
};
}
}
Click here to download the source file and .EXE
Output
|