Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am a beginner to this c++ language,a problem arised while del() function was carried out in my program which follows as:
C++
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<ctype.h>
#include<iomanip.h>

class student
{
	int admno;
	char name[35];
	float m_eng;
	float m_maths;
	float m_sc;
	float m_cmp;
	float perc;
	char grade;
     public:
	student()
	{
		m_eng=0;
		m_maths=0;
		m_sc=0;
		m_cmp=0;
		perc=0;
		grade= ' ';
	}
	void getdata();
	void putdata();
	void read();
	int getadmno()
	{
		return admno;
	}
	void calcres();
	void disp1(int);
	float ret_m_eng()
	{
		return m_eng;
	}
	float ret_m_maths()
	{
		return m_maths;
	}
	float ret_m_sc()
	{
		return m_sc;
	}
	float ret_m_cmp()
	{
		return m_cmp;
	}
};

void del(int rno)
{
	student stud;
	ifstream fio("student.dat",ios::in);
	ofstream file("temp.dat",ios::out);
	char found='f',confirm='n';
	while(!fio.eof())
	{
		fio.read((char*)&stud,sizeof(student));
		if(stud.getadmno()==rno)
		{
			stud.putdata();
			found='t';
			cout&lt;&lt;"    R u sure that u want 2 delete???";
			cin&gt;&gt;confirm;
			if(confirm=='n')
			file.write((char*)&stud,sizeof(student));
		}
		else
		file.write((char*)&stud,sizeof(student));
	}
	if (found=='f')
	cout&lt;&lt;"Record no found";
	fio.close();
	file.close();
	remove("student.dat");
	rename("temp.dat","student.dat");
}

void modify(int rno)
{
	student stud;
	int flag=0,rec=0;
	fstream fin("student.dat",ios::in|ios::out|ios::binary);
	if(fin==NULL)
	{
		cout&lt;&lt;"\n File does not exist.";
		return;
	}
	while(fin.read((char*)&stud,sizeof(student)))
	{
		rec++;
		if(rno==stud.getadmno())
		{
			gotoxy(21,16);cout&lt;&lt;"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»";
			gotoxy(21,17);cout&lt;&lt;"º                                      º";
			gotoxy(21,18);cout&lt;&lt;"º STUDENT DETAILS AT PRESENT ARE :     º";
			gotoxy(21,19);cout&lt;&lt;"º                                      º";
			gotoxy(21,20);cout&lt;&lt;"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ";
			stud.putdata();
			gotoxy(22,42);cout&lt;&lt;"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»";
			gotoxy(22,43);cout&lt;&lt;"º                                    º";
			gotoxy(22,44);cout&lt;&lt;"º Press any key to modify            º";
			gotoxy(22,45);cout&lt;&lt;"º                                    º";
			gotoxy(22,46);cout&lt;&lt;"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ";
			getch();
			clrscr();
			gotoxy(12,10);cout&lt;&lt;"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»";
			gotoxy(12,11);cout&lt;&lt;"º                                                      º";
			gotoxy(12,12);cout&lt;&lt;"º ENTER THE NEW DETAILS OF THE STUDENT  :              º";
			gotoxy(12,13);cout&lt;&lt;"º                                                      º";
			gotoxy(12,14);cout&lt;&lt;"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ";
			stud.read();
			fin.seekg((rec-1)*sizeof(student),ios::beg);
			fin.write((char*)&stud,sizeof(student));
			flag=1;
		}
	}
	if(flag==0)
	{
		gotoxy(14,20);cout&lt;&lt;"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»";
		gotoxy(14,21);cout&lt;&lt;"º                                                   º";
		gotoxy(14,22);cout&lt;&lt;"º THIS ROLL NUMBER DOES NOT EXIST                   º";
		gotoxy(14,23);cout&lt;&lt;"º                                                   º";
		gotoxy(14,24);cout&lt;&lt;"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ";

	}
	else
	{
		gotoxy(24,39);cout&lt;&lt;"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»";
		gotoxy(24,40);cout&lt;&lt;"º                                º";
		gotoxy(24,41);cout&lt;&lt;"º RECORD MODIFIED                º";
		gotoxy(24,42);cout&lt;&lt;"º                                º";
		gotoxy(24,43);cout&lt;&lt;"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ";
		return;
	}
	fin.close();
}


the del() fuction will be executed without any errors but when the program is runned evenif a record exist say it to be of admission no:1
in the output"Enter the admission no to delete the record of one who belongs to it ",evenif i give the admission no:as 1(which is existing )th o\p shwn is "the record doesnot exist",
i think that the while executing the program control doesnot enter the loop (while(fin.read((char*)&stud,sizeof(student))))
Posted
Updated 14-Oct-11 5:03am
v6
Comments
Reiss 14-Oct-11 10:33am    
Please don't code dump - I don't think many people are going spend the time to wade through all that
OriginalGriff 14-Oct-11 10:34am    
That is what is called a "Code Dump" and it is counted as very rude - hence the one-vote you have received from someone.
Don't just dump all your code on us; give us the relevant code fragments we need to help with your problem. No-body is going to just wade through all that looking for your routines, and your problem. And tell us what the problem is: "Please correct" is not very helpful when you don't tell us what it is even supposed to do...let alone what it isn't doing that it should or doing that it shouldn't.
Help us to help you.
Use the "Improve question" widget to edit your question and provide better information.
Ajay Mohan 14-Oct-11 10:49am    
sry ,told uam a beginner please excuse me for this time!!!!!!
OriginalGriff 14-Oct-11 10:54am    
Better - but you forgot to tell us what the problem is! (Don't re-enable the "Treat my content as plain text" option - it disables code formatting. It is only needed in very specific circumstances, none of which you are likely to meet for a while)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900