question telephone directory

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 3255 Views - Last Post: 01 October 2012 - 07:12 PM Rate Topic: -----

#16 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: question telephone directory

Posted 30 September 2012 - 12:28 PM

ok i am making an initializer list
is dat ok?
Was This Post Helpful? 0
  • +
  • -

#17 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: question telephone directory

Posted 30 September 2012 - 12:38 PM

Array <TD> a[5]={(5),(5),(5),(5),(5)}; this is the initialiser list of five objcts and size is 5
TD *a1=new TD[100]; dynamic pointer
is it correct
Was This Post Helpful? 0
  • +
  • -

#18 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: question telephone directory

Posted 30 September 2012 - 01:12 PM

First way to do it.
Here the Array object is not dynamically created. It could do with the default constructor of Array initializing the array to a default size, which doesn't happen at the moment.


class TelephoneEntries
{
  // one name and phone number
};


class TelephoneDirectory
{
  // Directory
  // Array of TelephoneEntries

  Array< TelephoneEntries > array;
};




Second way to do it.
This code uses a pointer to the array. In the default TelephoneDirectory constructor, new allocates memory and an Array is dynamically created. The value of 100 is passed as the size of the array, the Array class will create an array.



class TelephoneDirectory
{
  // Directory
  // Array of TelephoneEntries

  Array<TelephoneEntries> *array_ptr;

  TD() { array_ptr = new Array(100); } 
};


This post has been edited by #define: 30 September 2012 - 01:13 PM

Was This Post Helpful? 1
  • +
  • -

#19 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: question telephone directory

Posted 01 October 2012 - 02:06 AM

but cant i make only two classes i.e array class in header file and telephone directory class in application file???
also i m confused dat how many objects of array class be made in main function???
and will the array class and telephone directory class both have name and telephone numbr (data members) or only telephone dirctry class will have these data members????

and y cant i make object of aray class with default constructor. please i wana do it with parameterized constructor

and y cant i make object of aray class with parameterised** constructor. please i wana do it with parameterized constructor
Was This Post Helpful? 0
  • +
  • -

#20 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: question telephone directory

Posted 01 October 2012 - 07:06 AM

View Postmarriumkhan, on 01 October 2012 - 12:06 PM, said:

... cant i make only two classes i.e array class in header file and telephone directory class in application file?


Your array class can stay in header file and you can create the telephone directory class in application file.

Your instructions include :

View Postmarriumkhan, on 29 September 2012 - 08:55 PM, said:

Create an application class to represent telephone directory and provide the necessary member functions for operations that array class canít handle.


So you have the telephone directory class and the Array class which is two classes (so far).


View Postmarriumkhan, on 01 October 2012 - 12:06 PM, said:

... i m confused dat how many objects of array class be made in main function???
and will the array class and telephone directory class both have name and telephone numbr (data members) or only telephone dirctry class will have these data members?


A telephone directory has a list of names and numbers.
The Array class is used to store the list of names and numbers.
The telephone directory class has one object of Array.
An object/instance of the telephone directory class can be created in main.

The Array class is a template class which is passed a type to be used. Only one type can be used though. The telephone directory uses names and numbers (two strings?). Unless you want to use one string you will need a struct or class.



View Postmarriumkhan, on 01 October 2012 - 12:06 PM, said:

and y cant i make object of aray class with default constructor. please i wana do it with parameterized constructor

and y cant i make object of aray class with parameterised** constructor. please i wana do it with parameterized constructor



You can try this see if a constructor initializer list can work with C98.

class TelephoneEntries
{
  // one name and phone number
};


class TelephoneDirectory
{
  // Directory
  // Array of TelephoneEntries

  private:
    Array< TelephoneEntries > array;

  public:
    // using constructor initializer list
    TelephoneDirectory(int size) : array(size) {};
};


Was This Post Helpful? 1
  • +
  • -

#21 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: question telephone directory

Posted 01 October 2012 - 04:22 PM

but arnt u making another telephone entries class which makes it 3 clases :sweatdrop:
can i declare name and phone number in telepjhone directry class? :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#22 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: question telephone directory

Posted 01 October 2012 - 04:28 PM

this is the code but i havent made any telephone entries classs and i have made 5 objects of TD class is dat ok :dontgetit: ??
[/
//PERSONAL TELEPHONE DIRECTORY SYSTEM
#include"header.h"
#include<conio.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
class TD
{
char*name;
long tel;

public:

TD()
{
name=new char[20];
tel=0;
}
void setname(char*n)
{
strcpy(name,n);
}
void settel(long t)
{
tel=t;
}
char* getname()
{
return name;
}
long gettel()
{
return tel;
}
void writefile(TD t3,fstream fout);
void readfile(TD t2,fstream fin);
TD& operator=(TD t4)
{
strcpy(a,t4.name);
a=t4.settel(t);
}
TD& operator==(TD& d)
{
 if (strcmp(name==d.name)==0)
 return nn;
 else
 return 0;
}
friend ostream &operator<<( ostream &output, TD  &num);
friend istream &operator>>( istream &input, TD &num);
};
void TD::writefile(TD t3,fstream fout)
{
fout<<t3.getname()<<'\t'<<t3.gettel()<<endl;
}
void TD::readfile(TD t2,fstream fin)
{
char*nme=new char[20];
long tele;
fin>>nme>>tele;
t2.setname(nme);t2.settel(tele);
cout<<t2.getname()<<'\t'<<t2.gettel()<<endl;
}
ostream& operator<<( ostream &output, TD &num )
  {

	  output << num.getname()<<'\t'<<num.gettel()<<endl;
	  return output;

  }
istream& operator>>( istream &input, TD &num1)
 {
	  char*nnn;
	  long ttt;
	  cout<<" enter name and telephone "<<endl;
	  gets(nnn);
	  input>>ttt;
	  num1.setname(nnn) ;
	  num1.settel(ttt);

	  return input;
  }
void main()
{
clrscr();
Array <TD> a;
TD temp;
TD t[5];
char*str=new char[20];
fstream fout,fin;
cin>>str;            //ENTER FILE NAME FOR USER
fout.open(str,ios::out);
char*nn=new char[20];
for(int s=0;s<5;s++) //ENTERING DATA IN OBJECT OF TD
{
writefile(t[s],fout);  //WRITING RECORDS IN FILE
a.add(t[s]);        //INSERTING DATA IN ARRAY
}
cin>>temp;           //EDITING
a.edit(a,temp);

clrscr();
		  cout<<"\n*****ASSALAMOALAIKUM*****\n";
		  cout<<"1) Read phone list\n";
		  cout<<"2) Search for a phone number\n";
		  cout<<"3) Quit\n";
		  cout<<"Please enter your choice : "<<endl;
char choice;
cin>>choice;
switch(choice);
{
case 1:              //READ PHONE LIST
{
cout<<"enter phone file => ";
cin>>str;
fin.open(str,ios::in);
for(int iu=0;iu<5;iu++)
{
readfile(t[iu],fin);
a.add(t[iu]);        //STORING FILE DATA IN t1
a=t[iu];             //STORING t1 DATA IN ARRAY CLASS
}
cout<<iu<<" RECORDS ARE STORED "<<endl;
}
break;
case 2:              //SEARCHING BY NAME
{
char* nam=new char[20];
cout<<"enter person's name => "; //GETTING A NAME
gets(nam);
temp.setname(nam);
for(int j=0;j<5;j++) //SEARCHING ARRAY
{
a.search(temp);
}
cout<<a;
break;
}
case 3:             //QUIT
{
		  char exit_char;
		  cout <<"\nPress any key and <enter> to exit \n";
		  cin>> exit_char;
		  return 0;
 }
}
getch();
}

/]

MOD EDIT: PLEASE USE CODE TAGS WHEN POSTING CODE!!!

:code:

This post has been edited by jimblumberg: 01 October 2012 - 04:35 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.

Was This Post Helpful? 0
  • +
  • -

#23 jimblumberg  Icon User is offline

  • member icon


Reputation: 4233
  • View blog
  • Posts: 13,300
  • Joined: 25-December 09

Re: question telephone directory

Posted 01 October 2012 - 04:40 PM

You need to find an indentation style you like and use it consistently. This will make reading your code possible. No one wants to try to read through your unformatted mess and try to figure out what is wrong with your code.

Jim
Was This Post Helpful? 1
  • +
  • -

#24 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: question telephone directory

Posted 01 October 2012 - 04:47 PM

please tell me how to copy object name into the array of array class in operator= overload?
Was This Post Helpful? 0
  • +
  • -

#25 jimblumberg  Icon User is offline

  • member icon


Reputation: 4233
  • View blog
  • Posts: 13,300
  • Joined: 25-December 09

Re: question telephone directory

Posted 01 October 2012 - 04:50 PM

What have you tried? When you tell me what you have tried re-post your formatted code.

Jim
Was This Post Helpful? 1
  • +
  • -

#26 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: question telephone directory

Posted 01 October 2012 - 07:12 PM

View Postmarriumkhan, on 02 October 2012 - 02:22 AM, said:

but arnt u making another telephone entries class which makes it 3 clases :sweatdrop:
can i declare name and phone number in telepjhone directry class? :dontgetit:


How is the name and phone number entered into the Array?

A telephone directory is a collection or a group or a list of telephone entries.


Your instructions do not mention a limit on the number of classes. The instructions mention records, a record is closely associated with a struct. So would a struct be ok?


struct TelephoneEntries
{
  // one name and phone number record
};


class TelephoneDirectory
{
  // Directory
  // Array of TelephoneEntries

  private:
    Array< TelephoneEntries > array;

  public:
    // NOT using constructor initializer list
    TelephoneDirectory(int size)  { array.setsize(size);};
};


Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2