NOT ABLE TO GET THE OUTPUT.

NOT ABLE TO GET THE OUTPUT.

Page 1 of 1

2 Replies - 761 Views - Last Post: 03 January 2009 - 05:42 AM Rate Topic: -----

#1 kavyash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-December 08

NOT ABLE TO GET THE OUTPUT.

Posted 02 January 2009 - 01:08 PM

This is my project & i am in 12th. I am not able to get the output.can someone plz help me with this program. iam really in a pinch here.

/*Program Title : Address Book*/


#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
#include<iomanip.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void welcome_screen()
	 {
	clrscr();
	cout<<"\n\n\n\n ***************************************************************************";
cout<<"\n\t\t\tT E L E P H O N E  M A N A G E M E N T  S O F T W A R E   \t\t\t ";
cout<<"\n **************************************************************************";


	cout<<"***PRESS ANY KEY TO CONTINUE***";
	getch();
	return;
	 }
   class directory
	 {
	   public:
		   int record;
		   long pn1;
		   char pn2[10];
		   int age;
		   char address1[50];
		   char address2[50];
		   char occupation[20];
		   char name[20];
		   char emailadd[25];
		   void modification();
		   void addition();
		   void deleate();
		   void menu();
		   void search();
		   void view1();
		   void init();
		   void display();
		   void view();
		   char check(char *);
		   int test();
		}obj;
void directory::addition()
	{
	  ofstream fout;
	  fout.open("lucy",ios::out|ios::app);
	  init();
	  fout.write((char*)&obj,sizeof(obj));
	  fout.close();
	}
int directory::test()
	{
	  ifstream fin;
	  fin.open("lucy");
	  fin.seekg(0,ios::end);
	  int n;
	  n=fin.tellg()/sizeof(obj);
	  cout<<" \n NUMBER OF RECORDS = "<<n;
	  return n;
	}
void directory::search()
	{
	  ifstream fin;
	  fin.open("lucy");
	  if(fin.fail())
	{
	  cout<<" \n FILE NOT FOUND ";
	  getch();
	  return;
	}
	  clrscr();
	  cout<<" [SEARCHING] ";
	  cout<<" \n ENTER PHONE NUMBER TO BE SEARCHED : ";
	  long pn;
	  cin>>pn;
	  int n;
	  n=test();
	  for(int i=0;i<n;i++)
	{
	  fin.read((char*)&obj,sizeof(obj));
	  if(pn==pn1)
		{
		  view1();
		  return;
		}
	}
	  if(fin.eof())
	{
	  cout<<" \n RECORD NOT FOUND ";
	}
	}
void directory::init()
	{

	  clrscr();
	  char ch;
	  cout<<" [ADDITION] ";
	  cout<<" \n ENTER HOUSE PHONE NUMBER : ";
	  cin>>pn1;
	  cout<<" \n ENTER OFFICE PHONE NUMBER : ";
	  cin>>pn2;
	  cin.get(ch);
	  cout<<" \n ENTER NAME : ";
	  cin.getline(name,20,'\n');
	  cout<<" \n ENTER THE OCCUPATION : ";
	  cin.getline(occupation,20,'\n');
	  cout<<" \n ENTER HOUSE ADDRESS : ";
	  cin.getline(address1,50,'\n');
	  cout<<" \n ENTER OFFICE ADDRESS : ";
	  cin.getline(address2,50,'\n');
	  cout<<" \n ENTER EMAIL ADDRESS : ";
	  cin.getline(emailadd,25,'\n');

	}

void directory::view1()
	{
	  cout<<"\n";
	  cout<<" PHONE NUMBER1 : "<<obj.pn1<<"\n";
	  cout<<" PHONE NUMBER2 : "<<obj.pn2<<"\n";
	  cout<<" NAME : "<<obj.name<<"\n";
	  cout<<" HOUSE ADDRESS : "<<obj.address1<<"\n";
	  cout<<" OCCUPATION : "<<obj.occupation<<"\n";
	  cout<<" OFFICE ADDRESS : "<<obj.address2<<"\n";
	  cout<<" EMAIL ADDRESS : "<<obj.emailadd<<"\n";
	  getch();
	}
void directory::modification()
   {
	 clrscr();
	 cout<<" [ MODIFICATION ] ";
	 long pn;
	 int n,i;
	 ifstream fin;
	 ofstream fout;
	 fin.open("lucy");
	 if(fin.fail())
	   {
	 cout<<"\n FILE NOT FOUND !";
	 fout.close();
	 exit(-1);
	   }
	fout.open("new");
	n=test();
	if(n==0)
	  {
	cout<<"\n FILE IS EMPTY ! ";
	getch();
	return;
	  }
   while(fin.good())
	  {
	fin.read((char*)&obj,sizeof(obj));
	fout.write((char*)&obj,sizeof(obj));
	  }
   fin.close();
   fout.close();
   fout.open("lucy",ios::trunc);
   fin.open("new");
   if(fin.fail())
	 {
	  cout<<"\n FILE NOT FOUND !";
	  exit(-1);
	 }
   char ch;
   cout<<"\n ENTER PHONE NUMBER :";
   cin>>pn;
   ch=cin.get();

   for(i=0;i<n;i++)
	{
	   fin.read((char*)&obj,sizeof(obj));
	   char d;
	   if(pn==pn1)
		  {
		view1();
		d=check("HOUSE PHONE NUMBER ");
		if((d=='y') || (d=='Y'))
		  {
			cout<<"\n ENTER NEW PHONE NUMBER :";
			cin>>pn1;
			ch=cin.get();

		  }
		if(check("OFFICE PHONE NUMBER ")=='Y')
		  {
			cout<<"\n ENTER NEW PHONE NUMBER :";
			cin>>pn2;
		   ch=cin.get();

		  }
		if(check("NAME")=='y')
		  {
			cout<<"\n ENTER NEW NAME : ";
			cin.getline(name,20,'\n');
		  }
		if(check("HOME ADDRESS")=='y')
		  {
			cout<<"\n ENTER NEW ADDRESS :";
			cin.getline(address1,50,'\n');
		  }
		if(check("OFFICE ADDRESS")=='y')
		  {
			cout<<"\n ENTER NEW ADDRESS :";
			cin.getline(address2,50,'\n');
		  }
		if(check("EMAIL ADDRESS:")=='y')
		  {
			cout<<"\n ENTER NEW MAIL ADDRESS :";
			cin.getline(emailadd,25,'\n');
		  }

		  }
	   fout.write((char*)&obj,sizeof(obj));
	}
   fout.close();
   fin.close();
	}
char  directory::check(char *s)
	{
	   cout<<"\n MODIFY \t "<<s<<"\t"<<"Y/N";
	   char ch;
	  ch =getch();

	  if((ch=='y')||(ch=='Y'))
	return 'y';
	   else
	return 'n';
	}
void  directory::deleate()
	{
	   clrscr();
	   cout<<"[DELETION]";
	   long pn;
	   int n,i;
	   ifstream fin;
	   ofstream fout;
	   fin.open("lucy");
	   if(fin.fail())
	{
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	}
	   fout.open("new");
	   n=test();
	   if(n==0)
	{
	  cout<<"\n FILE IS EMPTY ! ";
	  getch();
	  return;
	}
	  for(i=0;i<n;i++)
	{
	  fin.read((char*)&obj,sizeof(obj));
	  fout.write((char*)&obj,sizeof(obj));
	}
	  fin.close();
	  fout.close();
	  fout.open("sakura",ios::trunc);
	  fin.open("new");
	  if(fin.fail())
	{
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	}
	 cout<<"\n ENTER PHONE NUMBER :";
	 cin>>pn;
	 for(i=0;i<n;i++)
	   {
	 fin.read((char*)&obj,sizeof(obj));
	 if(pn!=pn1)
		fout.write((char*)&obj,sizeof(obj));
	   }
	 fout.close();
	 fin.close();

	}
 void directory::view()
   {
	 ifstream fin;
	 int n,j;
	 fin.open("lucy");
	 if(fin.fail()||fin.bad())
	   {
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	   }
	 clrscr();
	 int i=0;
	 n=test();
	 for(j=0;j<n;j++)
	   {
	 cout<<"\n RECORD "<<i+1<<"\n";
	 fin.read((char*)&obj,sizeof(obj));
	 cout<<"\n PHONE NUMBER1 :"<<obj.pn1<<"\n";
	 cout<<"\n PHONE NUMBER2 :"<<obj.pn2<<"\n";
	 cout<<"\n NAME :"<<obj.name<<"\n";
	 cout<<"\n HOUSE ADDRESS :"<<obj.address1<<"\n";
	 cout<<"\n OCCUPATION :"<<obj.occupation<<"\n";
	 cout<<"\n OFFICE ADDRESS :"<<obj.address2<<"\n";
	 cout<<"\n EMAIL ADDRESS : "<<obj.emailadd<<"\n";
	 i+=1;
	   }
	  fin.close();
	  getch();

   }

void  directory::menu()
	{
	   char ch;
	   char option;
	   clrscr();

	   cout<<"\tFOR USERS CHOICE:\n\n";
	   cout<<"\t\t 1:ADDITION\n\n ";
	   cout<<"\t\t 2:DELETION \n\n";
	   cout<<"\t\t 3:MODIFICATION \n\n";
	   cout<<"\t\t 4:VIEW \n\n";
	   cout<<"\t\t 5:SEARCH \n\n";
	   cout<<"\t\t 6:EXIT \n\n";
	   cout<<"\t\t		  ENTER USER'S CHOICE:";
	   cin<<ch;

	  switch(ch)
	   {
		 case 1:addition();
			break;
		 case 2:deleate();
			break;
		 case 3:modification();
			break;
		 case 4:view();
			break;
		 case 5:search();
			break;
		 case 6:system("cls");
		 exit(0);
	 }


 }

int main()
	{
	  welcome_screen();
	  for(;;)
	  obj.menu();
	  return 0;
   }



Is This A Good Question/Topic? 0
  • +

Replies To: NOT ABLE TO GET THE OUTPUT.

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5316
  • View blog
  • Posts: 27,221
  • Joined: 10-May 07

Re: NOT ABLE TO GET THE OUTPUT.

Posted 02 January 2009 - 01:32 PM

Can you explain what you mean by "get the output"?
Was This Post Helpful? 0
  • +
  • -

#3 NoviceC++Programmer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 08

Re: NOT ABLE TO GET THE OUTPUT.

Posted 03 January 2009 - 05:42 AM

What u were trying to do?? and where the problem occured?
which compiler u r using here?

View Postkavyash, on 2 Jan, 2009 - 12:08 PM, said:

This is my project & i am in 12th. I am not able to get the output.can someone plz help me with this program. iam really in a pinch here.

/*Program Title : Address Book*/


#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
#include<iomanip.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void welcome_screen()
	 {
	clrscr();
	cout<<"\n\n\n\n ***************************************************************************";
cout<<"\n\t\t\tT E L E P H O N E  M A N A G E M E N T  S O F T W A R E   \t\t\t ";
cout<<"\n **************************************************************************";


	cout<<"***PRESS ANY KEY TO CONTINUE***";
	getch();
	return;
	 }
   class directory
	 {
	   public:
		   int record;
		   long pn1;
		   char pn2[10];
		   int age;
		   char address1[50];
		   char address2[50];
		   char occupation[20];
		   char name[20];
		   char emailadd[25];
		   void modification();
		   void addition();
		   void deleate();
		   void menu();
		   void search();
		   void view1();
		   void init();
		   void display();
		   void view();
		   char check(char *);
		   int test();
		}obj;
void directory::addition()
	{
	  ofstream fout;
	  fout.open("lucy",ios::out|ios::app);
	  init();
	  fout.write((char*)&obj,sizeof(obj));
	  fout.close();
	}
int directory::test()
	{
	  ifstream fin;
	  fin.open("lucy");
	  fin.seekg(0,ios::end);
	  int n;
	  n=fin.tellg()/sizeof(obj);
	  cout<<" \n NUMBER OF RECORDS = "<<n;
	  return n;
	}
void directory::search()
	{
	  ifstream fin;
	  fin.open("lucy");
	  if(fin.fail())
	{
	  cout<<" \n FILE NOT FOUND ";
	  getch();
	  return;
	}
	  clrscr();
	  cout<<" [SEARCHING] ";
	  cout<<" \n ENTER PHONE NUMBER TO BE SEARCHED : ";
	  long pn;
	  cin>>pn;
	  int n;
	  n=test();
	  for(int i=0;i<n;i++)
	{
	  fin.read((char*)&obj,sizeof(obj));
	  if(pn==pn1)
		{
		  view1();
		  return;
		}
	}
	  if(fin.eof())
	{
	  cout<<" \n RECORD NOT FOUND ";
	}
	}
void directory::init()
	{

	  clrscr();
	  char ch;
	  cout<<" [ADDITION] ";
	  cout<<" \n ENTER HOUSE PHONE NUMBER : ";
	  cin>>pn1;
	  cout<<" \n ENTER OFFICE PHONE NUMBER : ";
	  cin>>pn2;
	  cin.get(ch);
	  cout<<" \n ENTER NAME : ";
	  cin.getline(name,20,'\n');
	  cout<<" \n ENTER THE OCCUPATION : ";
	  cin.getline(occupation,20,'\n');
	  cout<<" \n ENTER HOUSE ADDRESS : ";
	  cin.getline(address1,50,'\n');
	  cout<<" \n ENTER OFFICE ADDRESS : ";
	  cin.getline(address2,50,'\n');
	  cout<<" \n ENTER EMAIL ADDRESS : ";
	  cin.getline(emailadd,25,'\n');

	}

void directory::view1()
	{
	  cout<<"\n";
	  cout<<" PHONE NUMBER1 : "<<obj.pn1<<"\n";
	  cout<<" PHONE NUMBER2 : "<<obj.pn2<<"\n";
	  cout<<" NAME : "<<obj.name<<"\n";
	  cout<<" HOUSE ADDRESS : "<<obj.address1<<"\n";
	  cout<<" OCCUPATION : "<<obj.occupation<<"\n";
	  cout<<" OFFICE ADDRESS : "<<obj.address2<<"\n";
	  cout<<" EMAIL ADDRESS : "<<obj.emailadd<<"\n";
	  getch();
	}
void directory::modification()
   {
	 clrscr();
	 cout<<" [ MODIFICATION ] ";
	 long pn;
	 int n,i;
	 ifstream fin;
	 ofstream fout;
	 fin.open("lucy");
	 if(fin.fail())
	   {
	 cout<<"\n FILE NOT FOUND !";
	 fout.close();
	 exit(-1);
	   }
	fout.open("new");
	n=test();
	if(n==0)
	  {
	cout<<"\n FILE IS EMPTY ! ";
	getch();
	return;
	  }
   while(fin.good())
	  {
	fin.read((char*)&obj,sizeof(obj));
	fout.write((char*)&obj,sizeof(obj));
	  }
   fin.close();
   fout.close();
   fout.open("lucy",ios::trunc);
   fin.open("new");
   if(fin.fail())
	 {
	  cout<<"\n FILE NOT FOUND !";
	  exit(-1);
	 }
   char ch;
   cout<<"\n ENTER PHONE NUMBER :";
   cin>>pn;
   ch=cin.get();

   for(i=0;i<n;i++)
	{
	   fin.read((char*)&obj,sizeof(obj));
	   char d;
	   if(pn==pn1)
		  {
		view1();
		d=check("HOUSE PHONE NUMBER ");
		if((d=='y') || (d=='Y'))
		  {
			cout<<"\n ENTER NEW PHONE NUMBER :";
			cin>>pn1;
			ch=cin.get();

		  }
		if(check("OFFICE PHONE NUMBER ")=='Y')
		  {
			cout<<"\n ENTER NEW PHONE NUMBER :";
			cin>>pn2;
		   ch=cin.get();

		  }
		if(check("NAME")=='y')
		  {
			cout<<"\n ENTER NEW NAME : ";
			cin.getline(name,20,'\n');
		  }
		if(check("HOME ADDRESS")=='y')
		  {
			cout<<"\n ENTER NEW ADDRESS :";
			cin.getline(address1,50,'\n');
		  }
		if(check("OFFICE ADDRESS")=='y')
		  {
			cout<<"\n ENTER NEW ADDRESS :";
			cin.getline(address2,50,'\n');
		  }
		if(check("EMAIL ADDRESS:")=='y')
		  {
			cout<<"\n ENTER NEW MAIL ADDRESS :";
			cin.getline(emailadd,25,'\n');
		  }

		  }
	   fout.write((char*)&obj,sizeof(obj));
	}
   fout.close();
   fin.close();
	}
char  directory::check(char *s)
	{
	   cout<<"\n MODIFY \t "<<s<<"\t"<<"Y/N";
	   char ch;
	  ch =getch();

	  if((ch=='y')||(ch=='Y'))
	return 'y';
	   else
	return 'n';
	}
void  directory::deleate()
	{
	   clrscr();
	   cout<<"[DELETION]";
	   long pn;
	   int n,i;
	   ifstream fin;
	   ofstream fout;
	   fin.open("lucy");
	   if(fin.fail())
	{
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	}
	   fout.open("new");
	   n=test();
	   if(n==0)
	{
	  cout<<"\n FILE IS EMPTY ! ";
	  getch();
	  return;
	}
	  for(i=0;i<n;i++)
	{
	  fin.read((char*)&obj,sizeof(obj));
	  fout.write((char*)&obj,sizeof(obj));
	}
	  fin.close();
	  fout.close();
	  fout.open("sakura",ios::trunc);
	  fin.open("new");
	  if(fin.fail())
	{
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	}
	 cout<<"\n ENTER PHONE NUMBER :";
	 cin>>pn;
	 for(i=0;i<n;i++)
	   {
	 fin.read((char*)&obj,sizeof(obj));
	 if(pn!=pn1)
		fout.write((char*)&obj,sizeof(obj));
	   }
	 fout.close();
	 fin.close();

	}
 void directory::view()
   {
	 ifstream fin;
	 int n,j;
	 fin.open("lucy");
	 if(fin.fail()||fin.bad())
	   {
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	   }
	 clrscr();
	 int i=0;
	 n=test();
	 for(j=0;j<n;j++)
	   {
	 cout<<"\n RECORD "<<i+1<<"\n";
	 fin.read((char*)&obj,sizeof(obj));
	 cout<<"\n PHONE NUMBER1 :"<<obj.pn1<<"\n";
	 cout<<"\n PHONE NUMBER2 :"<<obj.pn2<<"\n";
	 cout<<"\n NAME :"<<obj.name<<"\n";
	 cout<<"\n HOUSE ADDRESS :"<<obj.address1<<"\n";
	 cout<<"\n OCCUPATION :"<<obj.occupation<<"\n";
	 cout<<"\n OFFICE ADDRESS :"<<obj.address2<<"\n";
	 cout<<"\n EMAIL ADDRESS : "<<obj.emailadd<<"\n";
	 i+=1;
	   }
	  fin.close();
	  getch();

   }

void  directory::menu()
	{
	   char ch;
	   char option;
	   clrscr();

	   cout<<"\tFOR USERS CHOICE:\n\n";
	   cout<<"\t\t 1:ADDITION\n\n ";
	   cout<<"\t\t 2:DELETION \n\n";
	   cout<<"\t\t 3:MODIFICATION \n\n";
	   cout<<"\t\t 4:VIEW \n\n";
	   cout<<"\t\t 5:SEARCH \n\n";
	   cout<<"\t\t 6:EXIT \n\n";
	   cout<<"\t\t		  ENTER USER'S CHOICE:";
	   cin<<ch;

	  switch(ch)
	   {
		 case 1:addition();
			break;
		 case 2:deleate();
			break;
		 case 3:modification();
			break;
		 case 4:view();
			break;
		 case 5:search();
			break;
		 case 6:system("cls");
		 exit(0);
	 }


 }

int main()
	{
	  welcome_screen();
	  for(;;)
	  obj.menu();
	  return 0;
   }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1