Get the FREE certificate on C, C++, Java, Python, Perl, PHP, SQL, Linux & Javascript!  

CppBuzz.com
  
Home C C++ Java Python Perl PHP Spring SQL Javascript Linux Forum

You are here : Home » C++ projects » Project on College Registration

C++ project on college regisration

updateStudent#include <iostream>
#include <fstream>
#include <cstring>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

char studentsRecord[] = "studentRecord.txt";
char modulesRecord[] = "modulesRecord.txt";
char tempFile[] = "tempFile.txt";

class Student{

public:

//add one student's record to database
int addStudentRecord(char *studentsrecord){
	int studentNo;
	char name[50];
	
	std::ofstream outfile(studentsrecord, std::ios_base::app);
    
    cout<<"\n Enter Student No : ";
    cin>>studentNo;
    outfile<<endl<<studentNo<<" | ";
    
    cout<<"\n Enter Name of Student (50 char) : ";
    cin>>name;
    outfile<<name<<" | ";
    
    int flag=-1;
    cout<<"\n Enter 0 for Under Graduate, 1 for Post Graduate : ";
    cin>>flag;
    
    int moduleCount =-1;
    
    if(flag==0)
    moduleCount = 6;
    else if(flag ==1)
    moduleCount = 4;
    else{
    	cout<<"\n Error: Please enter either 0 or 1 ";
    	return -1;
	}
    
    for(int i=0; i<moduleCount; i++){
    	int module;
    	cout<<"\n Enter Module  No"<<i<<" : ";
    	cin>>module;
    	outfile<<module<<" | ";
	}
    
    char choice;
    cout<<"\n Do you want to add Marks against each module? y/n : ";
    cin>>choice;
    
    //separator to find start of marks
    outfile<<" = "; 
    
    if(choice=='y')
    {
    	for(int i=0; i<moduleCount; i++){
    	double marks;
    	cout<<"\n Enter Marks of Module  No"<<i<<" : ";
    	cin>>marks;
    	outfile<<marks<<" | ";
	}
    	
    }
       
outfile.close();  
}

//update any student's recrod to database
int updateStudentRecord(){
	int studentNo;
	cout<<"\n Enter Student Number :";
	cin>>studentNo;
	//modify if it exist e
}

//display record of any student by his student no
int displayStudentRecord(){
	int studentNo;
	
	//display if student record exist
	cout<<"\n ### Find Any Module Details ###\n\n";
	
	cout<<"\n Enter Student No to be searched: ";
	cin>>studentNo;

	int flag = -1;
	std::ifstream file(studentsRecord);
       string str;
  
  
	while (std::getline(file, str))
    {
    	if(str.length()>0){
    		
    		char temp[1000];
    		memset(temp,1000,sizeof(temp));
    		strcpy(temp, str.c_str());
    		
    		char * ptr;
			ptr = strtok(temp ,"|");
    		
    		int tempno = atoi(ptr);
    		
    		if(studentNo == tempno )
    		{
    			cout<<"\n "<<str;
    			flag = 1;
    			break;
			}
    		
		}
        
    }
    
    if(flag==-1)
    cout<<"\n No Student found with Student No : "<<studentNo;
    
    file.close();
	getchar();getchar();
}

//display record of all students
int displayAllStudentRecord(){
	std::ifstream file(studentsRecord);
    std::string str; 
    
    cout<<"\n ### List of All Student ###";
    
	if(!file)	{
		cout<<"\n No Record found !!";
		return -1;
	}
	
	
    while (std::getline(file, str))
    {
    	if(str.length()>0)
        cout<<"\n\t"<<str;
    }
    file.close();
    getchar();getchar();
}

int findStudentMarks(){
	cout<<"\n ### Find Marks of any Student ###\n\n";
	int studentNo;
	
	cout<<"\n Enter Student No : ";
	cin>>studentNo;

	int flag = -1;
	std::ifstream file(studentsRecord);
        string str;
  
  
    while (std::getline(file, str))
    {
    	if(str.length()>0){
    		
    		char temp[1000];
    		memset(temp,1000,sizeof(temp));
    		strcpy(temp, str.c_str());
    		
    		char * ptr;
			ptr = strtok(temp ,"|");
    		
    		int tempno = atoi(ptr);
    		
    		if(studentNo == tempno )
    		{
    			memset(temp,1000,sizeof(temp));
    		    strcpy(temp, str.c_str());
    			char *ptr1 = strtok(temp, "=");
    			ptr1 = strtok(NULL,"=");
    			//cout<<"\n====> "<<ptr1;
    			ptr1 = strtok(ptr1, "|");
    			double sum  = atof(ptr1);
    			double minNo = sum;
    			//cout<<"\n Min no is : "<< minNo;
    			int countSub = 0;
    			while(ptr1 = strtok(NULL,"|")){
    				//cout<<"-> "<<ptr1;
    				if(atof(ptr1)<minNo)
					minNo = atof(ptr1);
    				
    				sum += atof(ptr1);
    				countSub++;
				}
				
    			//cout<<"\n sum is : "<<sum;
    			//cout<<"\n count sub : "<<countSub;
    			//cout<<"\n MIn no is : "<<minNo;
    			
    			if(countSub == 6){
    				sum -= minNo;
    				cout<<"\n sum is : "<<sum;
    				sum = sum / 5; 
    				cout<<"\n Avg Sum is top 5 subjects: "<< sum<<endl;
    				
				if(sum>70) cout<<"\n Grade : A";
				else if(sum>=60 && sum<=69) cout<<"\n Grade is : B+";
				else if(sum >=50 && sum<=59) cout<<"\n Grade is : B";
				else if(sum>=41 && sum<=49) cout<<"\n Grade is : C";
				else if(sum>=40) cout<<"\n Grade is : D";
				else if(sum<40) cout<<"\n Grade is: F";
    				
				}
				else{
					sum = sum / 4; 
    				cout<<"\n Avg Sum of 4 subjects : "<< sum <<endl;
    				
    				if(sum>= 76) cout<<"\n Distinction";
					else if(sum>=61 && sum<=75 ) cout<<"\n Merit";
					else if(sum>=50 && sum<=60) cout<<"\n Pass";
					else if(sum<50) cout<<"\n Fail ";    				
				}
				
    			
    			
    			flag = 1;
    			break;
			}
    		
		}
        
    }
    
    if(flag==-1)
    cout<<"\n No Student found with Student No : "<<studentNo;
    
    file.close();
    getchar();getchar();
	
	
}

int updateStudent(){
	
    cout<<"\n ### Update Student Record  ###\n\n";
	int studentNo;
	
	cout<<"\n Enter Student No : ";
	cin>>studentNo;

	int flag = -1;
	std::ifstream file(studentsRecord);
    string str;
  
    
    int studentFound = 0;
	while (std::getline(file, str))
    {
    	if(str.length()>0){
    		
    		char temp[1000];
    		memset(temp,1000,sizeof(temp));
    		strcpy(temp, str.c_str());
    		
    		char * ptr;
			ptr = strtok(temp ,"|");
    		
    		int tempno = atoi(ptr);
    		
    		if(studentNo == tempno )
    		{
    			addStudentRecord(tempFile);
    			studentFound = 1;
    		}
    		else{
    			
    			std::ofstream file(tempFile, std::ios_base::app);
    			file<<endl<<str;
    			file.close();
    			
			}
    }
  }
  
  file.close();
  
  if(studentFound){
   remove(studentsRecord);
   rename(tempFile, studentsRecord);
  }
  
}
};

class Module{

public:

int displayAnyModuleInfo(){
	int moduleNo;	
	cout<<"\n ### Find Any Module Details ###\n\n";
	
	cout<<"\n Enter Module No to be searched : ";
	cin>>moduleNo;
	int flag = -1;
	std::ifstream file(modulesRecord);
    string str;
  
  
	while (std::getline(file, str))
    {
    	if(str.length()>0){
    		
    		char temp[1000];
    		memset(temp,1000,sizeof(temp));
    		strcpy(temp, str.c_str());
    		
    		char * ptr;
			ptr = strtok(temp ,"|");
    		
    		int tempno = atoi(ptr);
    		cout<<"\n Module no is : "<<temp;
    		
    		if(moduleNo == tempno )
    		{
    			cout<<"\n "<<str;
    			flag = 1;
    			break;
			}
    		
		}
        
    }
    
    if(!flag)
    cout<<"\n No Module found with Module No : "<<moduleNo;
    
    file.close();
	getchar();getchar();
	
	
}

int displayAllModulesInfo(){	
	cout<<"\n ### List of All Modules ###\n\n";
	
	//read all modules from record
	
	std::ifstream file(modulesRecord);
    std::string str; 
    cout<<"\n Module No | Title | Level";
    while (std::getline(file, str))
    {
    	if(str.length()>0)
        cout<<"\n"<<str;
    }
    file.close();
	getchar();getchar();
}

int updateModulesInfo(){
	cout<<"\n ### Update Module Info ###";
	int moduleNo;
	cout<<"\n Enter Module No to be modified:";
	cin>>moduleNo;
	
	//check if it exist & modified it
	
}

//add new module to database
int addModule(char *modulerecord){
	int moduleNo;
	char title[50];
	char level[50];
	
	std::ofstream outfile(modulerecord, std::ios_base::app);
    
    cout<<"\n ## Add New Module ###";
    
    cout<<"\n Enter Module No : ";
    cin>>moduleNo;
    outfile<<endl<<moduleNo<<" | ";
    
    cout<<"\n Enter Title of Module (50 char) : ";
    cin>>title;
    outfile<<title<<" | ";
    
    cout<<"\n Enter Levle of Module UnderGraduate/Graduate : ";
    cin>>level;
    outfile<<level<<" | ";   
    
    cout<<"\n Module Added Succesfully!!";
    getchar();
    
    outfile.close();  
}

int updateModule(){
	
	cout<<"\n ### Update Module Record  ###\n\n";
	int moduleNo;
	
	cout<<"\n Enter Module No : ";
	cin>>moduleNo;
	
	int flag = -1;
	std::ifstream file(modulesRecord);
	string str;
  
    
    int moduleFound = 0;
    while (std::getline(file, str))
    {
	if(str.length()>0){
		
		char temp[1000];
		memset(temp,1000,sizeof(temp));
		strcpy(temp, str.c_str());
		
		char * ptr;
			ptr = strtok(temp ,"|");
		
		int tempno = atoi(ptr);
		
		if(moduleNo == tempno )
		{
			addModule(tempFile);
			moduleFound = 1;
		}
		else{
			
			std::ofstream file(tempFile, std::ios_base::app);
			file<<endl<<str;
			file.close();
			
			}
	}
	}
  
  file.close();
  
  if(moduleFound){
   remove(modulesRecord);
   rename(tempFile, modulesRecord);
   }
  	
}
};

int main(int argc, char** argv) {
Student stdObject;
Module modObject;
	
int choice = -1;

while(choice !=0){
	system("cls");
	
	cout<<"\n ### College Registration System ###";
	cout<<"\n\n 1> Add Student Record";
	cout<<"\n 2> Update Student Record";
	cout<<"\n 3> Display any student record";
	cout<<"\n 4> Display all Student's record";
	cout<<"\n 5> Add Module";
	cout<<"\n 6> Display Any Module details";
	cout<<"\n 7> Display All Modules details";
	cout<<"\n 8> Update Module";
	cout<<"\n 9> Find Student Marks";
	cout<<"\n 0> Exit..";
	
	cout<<"\n\n Enter your choice : ";
	cin>>choice;
	
	
	switch(choice){
	case 1: stdObject.addStudentRecord(studentsRecord); break;
	case 2: stdObject.updateStudent(); break;
	case 3: stdObject.displayStudentRecord(); break; 
	case 4: stdObject.displayAllStudentRecord();break;
	case 5: modObject.addModule(modulesRecord); break;
	case 6: modObject.displayAnyModuleInfo(); break;
	case 7: modObject.displayAllModulesInfo(); break;
	case 8: modObject.updateModule(); break;
	case 9: stdObject.findStudentMarks(); break;
	case 0: cout<<"\n Thankyou for Using Software !! Good Bye\n "; break;
	default: cout<<"\n Invalid choice.."; getchar(); 
	}
}

return 0;
}

Program Output

college registration system

Class Diagram

C++ class diagram on school reservation system