13 Replies - 873 Views - Last Post: 14 July 2012 - 07:09 PM Rate Topic: -----

#1 ftitilade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-July 12

ERROR IN THE CODE

Posted 14 July 2012 - 03:20 PM

//*********************************************************//
//                 STUDENT MANAGEMENT SYSTEM BY DHUSKA    //
//*******************************************************//


#include<fstream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>


class student
{
	int studentid;
	char firstname;
	char lastname;
	char address;
	char city;
	char state;
	char country;
	char course;
public:
	void create_details();  //function to create student details
	void show_student();    //fucntion to show data on screen
	void modify();          //function to get new data from student
	void report();          // Function to show data in tabular format
	int retstudentid();         //function to return studentID
	char retcourse();        //function to return course
	
};   //end of class


void student::create_details()
{
	cout<<"\nEnter the studentID. ";
	cin>>studentid;
	cout<<"\nEnter the Student Firstname:";
	cin>>firstname;
	cout<<"\n\nEnter the student LastName: ";
	cin>>lastname;
	cout<<"\nEnter the student address: ";
	cin>>address;
	cout<<"\nEnter the City: ";
	cin>>city;
	cout<<"\nEnter the State: ";
	cin>>state;
	cout<<"\nEnter the Country: ";
	cin>>country;
	cout<<"\nEnter the Course: ";
	cin>>course;
	cout<<"\n\n\nStudent Details Created..";
}
	
void student::show_student()
{
	cout<<"\nStudentId  : "<<studentid;
	cout<<"\firstName   : "<<firstname;
	cout<<"\lastName   : "<<lastname;
	cout<<"\address    : "<<address;
	cout<<"\city       : "<<city;
	cout<<"state        : "<<state;
	cout<<"country      : "<<country;
	cout<<"course      : "<<course;
}

void student::modify()
{
	cout<<"\nThe StudentID. "<<studentid;
	cout<<"\n\nEnter the Student FirstName: ";
	cin>>firstname;
	cout<<"\n\nEnter the Student LastName: ";
	cin>>lastname;
	cout<<"\n\nEnter the student Address: ";
	cin>>address;
	cout<<"\n\nEnter the Student City: ";
	cin>>city;
	cout<<"\n\nEnter the Student State: ";
	cin>>state;
	cout<<"\n\nEnter the student Country: ";
	cin>>country;
	cout<<"\n\nEnter the Student Course: ";
	cin>>course;
}

void student::report()
{
	cout<<studentid<<setw(10)<<" "<<firstname<<setw(10)<<" "<<lastname<<setw(10)<<" "<<address<<setw(10)<<" "<<city<<setw(10)<<" "<<state<<setw(10)<<" "<<country<<setw(10)<<" "<<course<<endl;

void student::retstudentid()
{
	return studentid;
}

char student::retcourse()
{
	return course;
}



//******************************************************//
//               FUNCTION DECLARATION	               //
//****************************************************//

int main()
{
		char ch;
		int  id;
		clrscr();
		intro();
		do
		{
			clrscr();
			cout<<"\n\n\n\tMAIN MENU";
			cout<<"\n\n\t01. NEW STUDENT";
			cout<<"\n\n\t02. SEARCH FOR STUDENT";
			cout<<"\n\n\t03. ALL STUDENT LISt";
			cout<<"\n\n\t04. DELETE STUDENT";
			cout<<"\n\n\t05. MODIFY STUDENT DETAILS";
			cout<<"\n\n\t06. EXIT";
			cout<<"\n\n\tSELECT YOUR OPTION (1-6) ";
			cin>>ch
			clrscr();
			switch(ch)
			{
			case '1':
				write_details();
				break;
			case '2':
				cout<<"\n\n\tEnter the StudentID : ";cin>>id;
				display_st(id);
				break;
			case '3':
				display_all();
				break;
			case '4':
				cout<<"\n\n\tEnter the StudentID : ";cin>>id;
				delete_student(id);
				break;
			case '5':
				cout<<"\n\n\tEnter the StudentID : ";cin>>id;
				modify_details(id);
				break;
			case '6':
				cout<<"\n\n\tThank you for using the student management system";
				break;
			default :cout<<"\a";
			}
			getch();
		}while(ch!='6');
		return 0;
}


//*******************************************************//
//            FUNCTION TO WRITE TO FILE                 //
//*****************************************************//

void write_details()	
{
	student sid;
	ofstream outFile;
	outFile.open("student.dat",ios::binary|ios::app);
	sid.create_details();
	outFile.write((char *) &sid, sizeof(student));
	outFile.close();
}

//***************************************************//
//      FUNCTION TO READ SPECIFIC RECORD FROM FILE   //
//***************************************************//

void display_st(int n)
{
	student sid;
	int flag=0;
	instream inFile;
	inFile.open("student.dat",ios::binary);
	if(!inFile)
	{
		cout<<"File could not be open !!! Press any key.....";
	cout<<"\nStudent Details\n";
	while(inFile.read((char *) &sid, sizeof(student)))
	{
		if(sid.show_student()==n)
		{
			sid.show_student();
			flag=1;
		}
	}
	inFile.close();
	if(flag==0)
		cout<<"\n\nStudent Details does not exist";
}

//*************************************************//
//        FUNCTION TO MODIFY RECORD OF FILE        
//************************************************//

void modify_details(int n)
{
 	int found=0;
	student sid;
	fstream File;
	File.open("student.dat",ios::binary|ios::in|ios::out);
	if(!File)
	{	
		cout<<"File could not be open!! Press any Key....";
		return;
	}
	while(File.read((char *) &sid, sizeof(student)) && found==0)
	{
		if(sid.retstudentid()==n)
		{
		  	sid.show_details();
			cout<<"\n\nnEnter the New Student Details"<<endl;
			sid.modify();
			int pos=(-1)*sizeof(student);
			File.seekp(pos,ios::cur);
			File.write((char *) &sid, sizeof(student));
			cout<<"\n\n\t Record Updated!";
			found=1;
		}
	}
	File.close();
	if(found==0)
		cout<<"\n\n Record Not Found! ";
}


//*************************************************//
//         FUNCTION TO DELETE RECORD 
//************************************************//

void delete_student(int n)
{
	student sid;
	ifstream inFile;
	ofstream outFile;
	inFile.open("student.dat",ios::binary);
	if(!inFile)
	{
		cout<<"File could not be found!! Press any Key....";
		return;
	}
	outFile.open("Temp.dat"ios::binary);
	inFile.seekg(0,ios::beg);
	while(inFile.read((char *) &sid, sizeof(student)))
	{
		if(sid.retstudentid()!=n)
		{
			outFile.write((char *) &sid, sizeof(student));
		}
	}
	inFile.close();
	outFile.close();
	remove("student.dat");
	rename("Temp.dat","student.dat");
	cout<<"\n\n\tRecord Deleted!...";
}

//*************************************************//
//        FUNCTION TO DISPLAY ALL STUDENTS
//************************************************//

void display_all()
{
	student sid;
	ifstream inFile;
	inFile.open("student.dat",ios::binary);
	{
		cout<<"File could not be open!! Press any Key....";
		return;
	}
	cout<<"\n\n\t\tREGISTERED STUDENT LIST\n\n";
	cout<<"================================================================================\n";
	cout<<"STUDENTID     FIRSTNAME   LASTNAME   ADDRESS  CITY   STATE  COUNTRY COURSE"
	cout<<"==================================================================================\n";
	while(inFile.read((char *) &sid,sizeof(student)))
	{
		sid.report();
	}
	inFile.close();
}

void intro()
{
	cout<<"\n\n\n\t STUDENT";
	cout<<"\n\n\tMANAGEMENT";
	cout<<"\n\n\t SYSTEM";
	cout<<"\n\n\n\nMADE BY : DHUSKA";
	cout<<"\n\nSCHOOL: NIIT";
	getch();
}


//********************************************//
//             END OF PROJECT                 //
//*******************************************//


*** Edit ***
Please use code tags when posting code
Posted Image

PLEASE HELP ME CORRECT IT

This post has been edited by GunnerInc: 14 July 2012 - 03:20 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: ERROR IN THE CODE

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 864
  • View blog
  • Posts: 2,308
  • Joined: 28-March 11

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:21 PM

Ok there is an error. What kind of error? We are not mind readers.
Was This Post Helpful? 1
  • +
  • -

#3 ftitilade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-July 12

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:38 PM

View PostGunnerInc, on 14 July 2012 - 03:21 PM, said:

Ok there is an error. What kind of error? We are not mind readers.




Error: noname01.cpp(91,2):Identifier 'retstudentid' cannot have a type qualifier
Error: noname01.cpp(303,1):Declaration missing ;
Error: noname01.cpp(303,1):Compound statement missing }
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,439
  • Joined: 25-December 09

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:48 PM

What compiler are you using?

Part of your problem is that you are missing a closing brace for one of your functions, you also seem to be missing at least one include file.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 ftitilade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-July 12

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:51 PM

I am using Borland C can you please run it and try maybe you can fix the error for me please I really appreciate this.
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:51 PM

Hi,

void student::retstudentid()
	{
	    return studentid;
	}



it should be
int student::retstudentid()
	{
	    return studentid;
	}



as you specified in public:

void means it has no return value, which in this case it most certainly does

The rest I think you can work out yourself. (what is missing)

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,439
  • Joined: 25-December 09

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:56 PM

Quote

I am using Borland C can you please run it and try maybe you can fix the error for me please I really appreciate this.

Actually without changing several items I can't compile and run this program. You are using an old outdated compiler that uses old outdated header files. You should really find a newer compiler.

I already told you one of the things to look for, every opening brace { must be matched with a closing brace }. That should not be too difficult to find.

Jim
Was This Post Helpful? 0
  • +
  • -

#8 ftitilade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-July 12

Re: ERROR IN THE CODE

Posted 14 July 2012 - 03:59 PM

View Postsnoopy11, on 14 July 2012 - 03:51 PM, said:

Hi,

void student::retstudentid()
	{
	    return studentid;
	}



it should be
int student::retstudentid()
	{
	    return studentid;
	}



as you specified in public:

void means it has no return value, which in this case it most certainly does

The rest I think you can work out yourself. (what is missing)

Snoopy.



Thank you Snoopy but
I have used int it is not working
and I have try to fix the error it is not working help please
Was This Post Helpful? 0
  • +
  • -

#9 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: ERROR IN THE CODE

Posted 14 July 2012 - 04:11 PM

View Postftitilade, on 14 July 2012 - 10:59 PM, said:

Thank you Snoopy but
I have used int it is not working
and I have try to fix the error it is not working help please



That will only fix one error...

There are many, many errors with your program look above that procedure

You will see there is a '}' missing

look for '\' where it should be '\n'

Most of all be honest with us about how many errors you have
when you can do all that come back and talk to us.

Snoopy.

This post has been edited by snoopy11: 14 July 2012 - 04:11 PM

Was This Post Helpful? 0
  • +
  • -

#10 ftitilade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-July 12

Re: ERROR IN THE CODE

Posted 14 July 2012 - 04:17 PM

View Postjimblumberg, on 14 July 2012 - 03:56 PM, said:

Quote

I am using Borland C can you please run it and try maybe you can fix the error for me please I really appreciate this.

Actually without changing several items I can't compile and run this program. You are using an old outdated compiler that uses old outdated header files. You should really find a newer compiler.

I already told you one of the things to look for, every opening brace { must be matched with a closing brace }. That should not be too difficult to find.

Jim




thanks Jim
I used c-free it gave me these error

--------------------Configuration: mingw5 - CUI Debug, Builder Type: MinGW--------------------


[Error] C:\Users\TVITALITY\Documents\C-Free\Temp\Untitled1.cpp:91: error: a function-definition is not allowed here before '{' token
[Error] C:\Users\TVITALITY\Documents\C-Free\Temp\Untitled1.cpp:96: error: a function-definition is not allowed here before '{' token
[Error] C:\Users\TVITALITY\Documents\C-Free\Temp\Untitled1.cpp:107: error: a function-definition is not allowed here before '{' token
[Error] C:\Users\TVITALITY\Documents\C-Free\Temp\Untitled1.cpp:161: error: a function-definition is not allowed here before '{' token
[Error] C:\Users\TVITALITY\Documents\C-Free\Temp\Untitled1.cpp:175: error: a function-definition is not allowed here before '{' token
[Error] C:\Users\TVITALITY\Documents\C-Free\Temp\Untitled1.cpp:295: error: expected `}' at end of input

Complete Make Untitled1: 6 error(s), 3 warning(s)
Was This Post Helpful? 0
  • +
  • -

#11 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: ERROR IN THE CODE

Posted 14 July 2012 - 04:20 PM

Once you replace the missing brace '}' on line 89

you will see a raft of new errors I promise you.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#12 JesseLord  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 42
  • Joined: 24-May 10

Re: ERROR IN THE CODE

Posted 14 July 2012 - 05:04 PM

I also so a missing semicolon in DisplayAll().
Was This Post Helpful? 0
  • +
  • -

#13 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5393
  • View blog
  • Posts: 27,387
  • Joined: 10-May 07

Re: ERROR IN THE CODE

Posted 14 July 2012 - 05:52 PM

View Postsnoopy11, on 14 July 2012 - 07:11 PM, said:

View Postftitilade, on 14 July 2012 - 10:59 PM, said:

Thank you Snoopy but
I have used int it is not working
and I have try to fix the error it is not working help please



That will only fix one error...

There are many, many errors with your program look above that procedure

To the OP : This is why you should program in chunks, & not code the entire program all at once & then chaise every error. Program it in segments that you understand what is happening, find the little errors before the project gets too large. I've been programing for many, many years, & I still don't code more than 10 or so lines before I test compile.
Was This Post Helpful? 1
  • +
  • -

#14 FrozenSnake  Icon User is online

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 1,005
  • Joined: 30-July 08

Re: ERROR IN THE CODE

Posted 14 July 2012 - 07:09 PM

I see that you are using function you haven't declared yet. If you are putting a function under your main() function you HAVE TO declare it above main().

example
#include <iostream>
using namespace std;

void returnSum(int x, int y); // without this you cannot use returnSum() in main()

int main()
{
    returnSum(1, 3);
    return 0;
}

void returnSum(int x, int y)
{
    cout << x + y << endl;
}
Otherwise your compiler won't know it exist. Either you do like this or you put the function above the main() or in a separate file all together.

Your code is also missing a lot of ';', '}' etc. Like on line 126
			cin>>ch
you have forgot to add ; in the end. There is A LOT of errors in this code, and you will have to read the error, go to the line its telling you too OR the one above and correct these.

Either you rewrite everything and do not copy paste anything from your old code, or you check each error and fix them. It might be annoying but it's your homework to get this program up-and-running! If we sit here and fix every single error for you and just show you the code you will not (no matter what you say) read the code and learn from it, you will compile it, see that it works and turn it in without understanding why it is working (No offence).

Regarding compiler/editor. If you are forced to use Turbo C you should ask your teacher why s/he uses a outdated thing like Turbo C. If you doesn't have to use Turbo C you could always download Code::Block together with mingw (it is included in at least the window version)! It's free and available on Windows, Linux and Mac OS X.

Or if you prefer you can use Visual Studio Express which is also free to use for non-commercial projects!

This post has been edited by FrozenSnake: 14 July 2012 - 07:10 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1