-->




student record c++ programming project for beginners

2 comments
Project Introduction and scope
It is a simple c++ project for beginners to cover some basic topics. Which can help c++ beginners to build large projects and gives idea about how to make project in c++ programming. To keep the project simple only basic functionalities has added it is recommended for students first understand the project flow then add more functions like edit record (hint code also has given below) etc. Best practice for students is to first add validation in this project which will not allow user to enter wrong option and then add more functions.

It includes the concept of following topics

  • struct 
  • Filing 
  • Loops
  • Arrays
  • If else
  • Switch statement
  • String class functions
Project has for major functions in menu

  1. Insert record
  2. Show all record
  3. Search record
  4. Exit program
How it works
Each  functionality has a function call in switch statement on the user choice control transfers to a function. Every function opens a file name "database" and insert, show and search data from it. File will be created where c++ file is placed in secondary storage.

C++ project source code

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>

struct student
{
 char name[20];
 char reg[15];
 char course[10];
 float cgpa;
};

fstream file;
student obj;

void add()
{
 cout<<"Enter Name: ";
 cin>>obj.name;
 cout<<"Enter Registration Number: ";
 cin>>obj.reg;
 cout<<"Enter Course: ";
 cin>>obj.course;
 cout<<"Enter CGPA: ";
 cin>>obj.cgpa;

 file.open("database.txt",ios::app) ;
 file.write((char*)&obj,sizeof(obj));
 file.close();
}

void show_all()
{     //  clrscr();
 file.open("database.txt",ios::in);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  cout<<"Name: "<<obj.name<<endl;
  cout<<"Registration Number: "<<obj.reg<<endl;
  cout<<"Course: "<<obj.course<<endl;
  cout<<"CGPA: "<<obj.cgpa<<endl<<endl;

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}

void search()
{      // clrscr();
 float user;
 cout<<"Enter CGPA: ";
 cin>>user;
 file.open("database.txt",ios::in);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  if (obj.cgpa==user)
  {
   cout<<"Name: "<<obj.name<<endl;
   cout<<"Registration Number: "<<obj.reg<<endl;
   cout<<"Course: "<<obj.course<<endl;
   cout<<"CGPA: "<<obj.cgpa<<endl<<endl;
  }

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}

void edit()
{     //  clrscr();

 char user[15];
 cout<<"Enter registration Number: ";
 cin>>user;

 file.open("database.txt",ios::in|ios::out);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  if (strcmp(obj.reg,user)==0)
  {
   cout<<"Name: "<<obj.name<<endl;
   cout<<"Registration Number: "<<obj.reg<<endl;
   cout<<"Course: "<<obj.course<<endl;
   cout<<"CGPA: "<<obj.cgpa<<endl<<endl;

   cout<<"\nEnter New course: ";
   cin>>obj.course;

   file.seekp(file.tellg()-sizeof(obj));
   file.write((char*)&obj,sizeof(obj));
   cout<<"\n\nFile Updated";
   break;
  }

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}


void main()
{
// clrscr();

 //file.open("c:\database.txt",ios::out);
 //file.close();
 int option;

 while(1)
 {
 // clrscr();
  cout<<"Enter 1 to Enter Record\n";
  cout<<"Enter 2 to Show All Record\n";
  cout<<"Enter 3 to Search Record\n";
  cout<<"Enter 4 to Exit\n";
  cout<<"\n\nEnter Option: ";
  cin>>option;

  switch (option)
  {
   case 1:
    add();
    cout<<"\n\nRecord Entered\n";
    getch();
    break;
   case 2:
    show_all();
    break;
   case 3:
    search();
    break;
   case 4:
    exit(0);
  }
 }
 getch();
}


sample input output
student record c++ programming project for beginners


Source code has been tested on Microsoft Visual C++ compiler. If you are running on a different compiler like codeBlocks. Some changes may required like add using namespace std; , remover .h from iostream etc.

Reference edit functionality c++ source code for practice

void edit()
{     //  clrscr();

 char user[15];
 cout<<"Enter registration Number: ";
 cin>>user;

 file.open("database.txt",ios::in|ios::out);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  if (strcmp(obj.reg,user)==0)
  {
   cout<<"Name: "<<obj.name<<endl;
   cout<<"Registration Number: "<<obj.reg<<endl;
   cout<<"Course: "<<obj.course<<endl;
   cout<<"CGPA: "<<obj.cgpa<<endl<<endl;

   cout<<"\nEnter New course: ";
   cin>>obj.course;

   file.seekp(file.tellg()-sizeof(obj));
   file.write((char*)&obj,sizeof(obj));
   cout<<"\n\nFile Updated";
   break;
  }

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}


Hope this code will help. Check also
School management c++ project source code. To check some example codes see more at  simple c++ code examples.
Read More...

Difference between iteration and recursion c++ example

Leave a Comment
Major difference and similarities between recursion and iteration
  • Both works repeatedly, iteration uses loops and recursion uses functions call 
  • Both have termination cases one has a relation expression in loop and one has a base case in if conditoin
  • Iteration checks repeatedly its relational expression and recursion checks repeatedly its base case
  • Iteration control by counter variable and recursion by its base case
  • Both can be run infinitely when loops condition never false and base case if condition never becomes true

Memory differences
In case of recursion every calls put on stack and save into memory the more calls more memory consumption. In worst case if base case never becomes true or programmer has forget to write base case it will cause stack over flow and at some point you will see calls has stopped. In case of loop it will run infinitely and never stops.


Which one to choose?
It depends on the requirement both are not superior to each other in every scenario both have their own benefits and draw backs in different conditions.
For example if you want to write the Fibonacci series program in c++ using loop then it may 
  • hard to write  
  • less overhead to memory 
  • less readable
If you use recursion function code 
long fib(long n) {
    if (n <= 1) return n;
    else return fib(n-1) + fib(n-2);
}

(See example at StackOverFlow.com)
It looks 
  • More readable
  • High memory consumption 
  • Easy to write if you have the good concept of recursion
Read More...

string class function memchr c example

2 comments
In string class memchr() function helps us to find a byte within a specific memory block. It takes three parameters memchr(buffer, char, size); and returns pointer to first occurrence where char is found else it returns NULL.



Buffer: Memory block in which a byte to be searched
char: Character to search in buffer
size: Size of buffer.

C++ source code: Compiler used CodeBlocks

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main ()
{
    char buffer[] = "I like c++ programming";
    cout<<"We have this string -> \n";
    puts(buffer);
    char key;
    char *result;
    cout<<"Enter a character to search in string:  ";
    cin>>key;
    cout<<endl;

    result = (char*)memchr(buffer, key, strlen(buffer));

    if (result!=NULL)
        cout<<key<<" is found at index number:  "<<(result-buffer) ;
     else
        cout<<" NOT FOUND";
    
    cout<<endl;
 return 0;
}


Input output code


program output
string class function memchr c++ example





Read More...

School Management Simple C++ Project Source Code

2 comments
This school management C++ project for beginners contains both student and teacher record management system. In which a menu consist of two options to enter data for student or teacher. It has two structures one for student and one for teacher's data. Main screen displays a menu option through which user press option for student, teacher or to end program. Comments are used to explain the source code. User can download this project, run and make changes.

Scope
This project is helpful for C++ beginner students. They can add more functions according to their need. Project is simple and less complex.
It includes following concepts
  • file handling <fstream>
  • struct
  • Loops
  • Switch
  • if else statement
  • string class <string>
It has tested on Visual studio

Project Source code

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SCHOOL MANAGEMENT PROGRAM

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//Headers inclusion

#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <windows.h>

using namespace std;

//Structure defining

//For students
struct student
{
 string fname;//for student first name
 string lname;//for student last name
 string Registration;//for Registration No number
 string classes;//for class info
}studentData;//Variable of student type

//For teachers
struct teacher
{
 string fst_name;//first name of teacher
 string lst_name;//last name of teacher
 string qualification;//Qualification of teacher
 string exp;//Experiance of the person
 string pay;//Pay of the Teacher
 string subj;//subject whos he/she teach
 string lec;//Lecture per Week
 string addrs;//Adders of teacher home
 string cel_no;//Phone number 
 string blod_grp;//Bool Group 
 string serves;//Number of serves in School

}tech[50];//Variable of teacher type

///////////////////////////////////////////////////
//Main function

void main()
{

int i=0,j;//for processing usage 
char choice;//for getting choice
string find;//for sorting
string srch;

while(1)//outer loop
{ 
 system("cls");//Clear screen

//Level 1-Display process 
 cout<<"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\";
 cout<<"\n\n\t\t\tSCHOOL MANAGEMENT PROGRAM\n\n";
 cout<<"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\";
 cout<<"\n\n\t\t\tMAIN SCREEN\n\n";
 cout<<"Enter your choice: "<<endl;
 cout<<"1.Students information"<<endl;
 cout<<"2.Teacher information"<<endl;
 cout<<"3.Exit program"<<endl;
 cin>>choice;

system("cls");//Clear screen


switch(choice)//First switch
{
 
case '1': //Student
 { 
while(1)//inner loop-1
{ 
system("cls");//Clear screen
//Level-2 display
cout<<"\t\t\tSTUDENTS INFORMATION AND BIO DATA SECTION\n\n\n";
cout<<"Enter your choice: "<<endl;
cout<<"1.Create new entry\n";
cout<<"2.Find and display entry\n";
cout<<"3.Jump to main\n";
cin>>choice;

switch (choice)//Second switch

{
case '1'://Insert data
{  ofstream f1("student.txt",ios::app);

for( i=0;choice!='n';i++)
{

if((choice=='y')||(choice=='Y')||(choice=='1'))
{
 cout<<"Enter First name: ";
 cin>>studentData.fname;
 cout<<"Enter Last name: ";
 cin>>studentData.lname;
 cout<<"Enter Registration number: ";
 cin>>studentData.Registration;
 cout<<"Enter class: ";
 cin>>studentData.classes;
 
 f1<<studentData.fname<<endl<<studentData.lname<<endl<<studentData.Registration<<endl<<studentData.classes<<endl;
 cout<<"Do you want to enter data: ";
 cout<<"Press Y for Continue and N to Finish:  ";
 cin>>choice;
}
} 
f1.close();
}
continue;//control back to inner loop -1

case '2'://Display data
{  ifstream f2("student.txt"); 

cout<<"Enter First name to be displayed: ";
cin>>find;
cout<<endl;
int notFound = 0;
for( j=0;(j<i)||(!f2.eof());j++)
{ 

getline(f2,studentData.fname);

if(studentData.fname==find)
{
 notFound = 1;
 cout<<"First Name: "<<studentData.fname<<endl;
 cout<<"Last Name: "<<studentData.lname<<endl;

 getline(f2,studentData.Registration);
 cout<<"Registration No number: "<<studentData.Registration<<endl;
 getline(f2,studentData.classes);
 cout<<"Class: "<<studentData.classes<<endl<<endl;
}

}

if(notFound == 0){

cout<<"No Record Found"<<endl;
}
f2.close();
cout<<"Press any key two times to proceed";
getch();//To hold data on screen
getch();//To hold data on screen

}
continue;//control back to inner loop -1

case '3'://Jump to main
{
break;//inner switch breaking
}
}

break;//inner loop-1 breaking
}
continue;//Control pass to 1st loop    
}

case '2'://Teachers biodata
{ 
while(1)//inner loop-2
{ 
system("cls");//Clear screen
//Level-2 Display process
cout<<"\t\t\tTEACHERS INFORMATION AND BIODATA SECTION\n\n\n";
cout<<"Enter your choice: "<<endl;
cout<<"1.Create new entry\n";
cout<<"2.Find and display\n";
cout<<"3.Jump to main\n";
cin>>choice;

switch (choice)//Third switch
{
case '1'://Insert data
{ 
ofstream t1("teacher.txt",ios::app);

for(i=0;choice!='n'&& choice!='N';i++)
{
 
 if((choice=='y')||(choice=='Y')||(choice=='1'))
 {
  cout<<"Enter First name: ";
  cin>>tech[i].fst_name;
  cout<<"Enter Last name:: ";
  cin>>tech[i].lst_name;
  cout<<"Enter qualification: ";
  cin>>tech[i].qualification;
  cout<<"Enter experiance(year): ";
  cin>>tech[i].exp;
  cout<<"Enter number of year in this School: ";
  cin>>tech[i].serves;
  cout<<"Enter Subject whos teach: ";
  cin>>tech[i].subj;
  cout<<"Enter Lecture(per Week): ";
  cin>>tech[i].lec;
  cout<<"Enter pay: ";
  cin>>tech[i].pay;
  cout<<"Enter Phone Number: ";
  cin>>tech[i].cel_no;
  cout<<"Enter Blood Group: ";
  cin>>tech[i].blod_grp;
  
  
  t1<<tech[i].fst_name<<endl<<tech[i].lst_name<<endl 
   <<tech[i].qualification<<endl<<tech[i].exp<<endl
   <<tech[i].serves<<endl<<tech[i].subj<<endl<<tech[i].lec
   <<endl<<tech[i].pay<<endl<<tech[i].cel_no<<endl<<tech[i].blod_grp<<endl;
  cout<<"Do you want to enter data: ";
  cin>>choice;
 }//if
}//for loop
//for finding through name 
system("cls");



t1.close();
}//case 1

continue;//Control pass to inner loop-2

case '2'://Display data
{ 
ifstream t2("teacher.txt"); 

cout<<"Enter name to be displayed: ";
cin>>find;

cout<<endl;
int notFound = 0;
for( j=0;((j<i)||(!t2.eof()));j++)
{ 
 
 getline(t2,tech[j].fst_name);
 
 if(tech[j].fst_name==find)
 {
  notFound = 1;
  cout<<"First name: "<<tech[j].fst_name<<endl;
  getline(t2,tech[j].lst_name);
  cout<<"Last name: "<<tech[j].lst_name<<endl;
  getline(t2,tech[j].qualification);
  cout<<"Qualification: "<<tech[j].qualification<<endl;
  getline(t2,tech[j].exp);
  cout<<"Experience: "<<tech[j].exp<<endl;

  getline(t2,tech[j].serves);
  cout<<" number of year in this School: "<<tech[j].serves<<endl;

  getline(t2,tech[j].subj);
  cout<<"Subject whos teach: "<<tech[j].subj<<endl;

  getline(t2,tech[j].lec);
  cout<<"Enter Lecture(per Week): "<<tech[j].lec<<endl;
  getline(t2,tech[j].pay);
  cout<<"pay: "<<tech[j].pay<<endl;

  getline(t2,tech[j].addrs);
  cout<<"Address: "<<tech[j].addrs<<endl;

  getline(t2,tech[j].cel_no);
  cout<<"Phone Number: "<<tech[j].cel_no<<endl;

  getline(t2,tech[j].blod_grp);
  cout<<"Bool Group: "<<tech[j].blod_grp<<endl;
 }//if
 
}//for loop
t2.close();
if(notFound == 0){

 cout<<"No Record Found"<<endl;
}
cout<<"Press any key two times to proceed";
getch();//To hold data on screen
getch();//To hold data on screen
}//case 2

continue;//Control pass to inner loop-2

case '3'://Jump to main 
{
break;//inner switch
}//case 3

}//inner switch

break;//inner while
}//inner loop

continue;//control pass to 1st loop
}//outer case 2


case '3':
{
break;//outer case 3
}//outer case 3
}   
break;//outer loop
}


}


School Management C++ Project Source Code Download
Watch Output



Menu output
C++ school management project for beginners



It is recommended that first run the project then understand the flow of program. Add new functionalities like delete a record etc using functions will very helpful to learn.
See here some basic Example of C++ Programs if a piece of code in project is difficult to understand then first see a simple example then come back to project.


Read More...