![]() | ||||
#include <fstream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
struct student{
char personname[20][20];
char phone[20][20];
int counter;
};
int counter = 0;
myappend(student &info)
{
cout<<"ENTER PERSON NAME ";
cin>> info.personname[counter];
cout<<"ENTER THE PHONE ";
cin>> info.phone[counter];
counter++;
cout<<"COUNTER IS
"<<counter<<endl;
return 0; }//MY APPEND
mysearch(student &info)
{
char searchname[20];
cout<<"ENTER THE SEARCH NAME ";
cin>>searchname;
for(int i = 0; i<counter;i++){
if(strcmp(searchname,info.personname[i])==0){
cout<<"THE PHONE IS "<<info.phone[i]
<< endl << endl;
cout<<"COUNTER IS
"<<counter<<endl;
return 1; }//IF
}//wfor
cout<<"NAME NOT FOUND" <<endl;
return 0;
}//MYSEARCH
mydisplay(student &info)
{
for(int i= 0; i<counter;i++){
cout<<"Person Name Is "<<
info.personname[i]<<endl;
cout<<"PHONE IS
"<<info.phone[i]<<endl; }//while
return 0;
} //mydisplay
mymodify(student &info)
{
char searchname[20], newphone[20];
cout<<"ENTER A NAME TO MODIFY THE PHONE#
"<<endl;
cin>>searchname;
for (int i=0; i<counter; i++)
{
if(strcmp(searchname,info.personname[i])==0){
cout<<"ENTER THE NEW PHONE NUMBER FOR THIS PERSON
"<<endl;
cin>>newphone;
strcpy(info.phone[i], newphone);
return 1;
}//endif
cout<<"NAME NOT FOUND "<<endl;}
return 0;}
mydelete(student &info){
char searchname[20];
cout<<"ENTER THE DELETE NAME "<<endl;
cin>>searchname;
for(int i = 0; i<counter; i++){
if(strcmp(searchname, info.personname[i])==0){
strcpy(info.personname[i],"");
strcpy(info.phone[i],"");
return 1;}
}
cout<<"NAME NOT
FOUND"<<endl<<endl;
return 0;
}//mydelete
int loadintoarray(student &info){
ifstream fin("directory.txt");
while(fin>>info.personname[counter]>>info.phone[counter])
counter++;
fin.close();
return 0;}//loadintoarray
int storetofile(student &info){
ofstream fout("directory.txt",ios::out);
for(int i = 0; i<counter; i++){
fout<<setw(20)<<info.personname[i]<<setw(20)<<info.phone[i]<<endl;
return 0;}
main()
{
student info;
char option;
//char personname[20][20],phone[20][20];
loadintoarray(info);
cout<<"SELECT ONE OF THE
FOLLOWING"<<endl;
while(1){
cout<<"TYPE 1 TO INSERT "<<endl;
cout<<"type 2 to display "<<endl;
cout<<"type 3 to search " << endl;
cout<<"TYPE 4 TO MODIFY " <<endl;
cout<<"TYPE 5 TO DELETE " <<endl;
cout<<"type # to quit "<<endl;
cin>>option;
if(option=='1') myappend(info);
else if (option=='2') mydisplay(info);
else if (option=='3') mysearch (info);
else if (option=='4') mymodify (info);
else if (option=='5') mydelete (info);
else if(option=='#') {
storetofile(info);
cout<<"BYE"<<endl;
exit(1);
}
}//while
return 0;
}//ENDMAIN
BACK TO THE MENU
#include <fstream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
class student
{
private:char personname[20][20];
char phone[20][20];
int counter;
public: student ()
{
counter = 0;
}
int myappend();
int mysearch();
int mydisplay();
};
main()
{
student info;
char option;
int counter = 0;
cout<<"SELECT ONE OF THE FOLLOWING"<<endl;
while(1){
cout<<"TYPE 1 TO INSERT "<<endl;
cout<<"type 2 to display "<<endl;
cout<<"type 3 to search " << endl;
cout<<"type # to quit "<<endl;
cin>>option;
if(option=='1') info.myappend();
else if (option=='2') info.mydisplay();
else if (option=='3') info.mysearch ();
else if(option=='#') {cout<<"BYE"<<endl;
exit(1);
}
}//while
return 0;
}//main
int student:: myappend()
{
cout<<"ENTER PERSON NAME ";
cin>> personname[counter];
cout<<"ENTER THE PHONE ";
cin>> phone[counter];
counter++;
cout<<"COUNTER IS "<<counter<<endl;
return 0; }//MY APPEND
int student::mysearch()
{
char searchname[20];
cout<<"ENTER THE SEARCH NAME ";
cin>>searchname;
for(int i = 0; i<counter;i++){
if(strcmp(searchname,personname[i])==0){
cout<<"THE PHONE IS "<<phone[i] << endl << endl;
cout<<"COUNTER IS "<<counter<<endl;
return 1; }//IF
}//wfor
cout<<"NAME NOT FOUND" <<endl;
return 0;
}//MYSEARCH
int student::mydisplay()
{
for(int i= 0; i<counter;i++){
cout<<"Person Name Is "<<personname[i]<<endl;
cout<<"PHONE IS "<<phone[i]<<endl; }//while
return 0;
} //mydisplay
BACK TO
THE MENU
CLICK ON THIS WEBSITE
TEN COMMANDMENTS
BACK TO THE MENU
BACK TOTHE MENU
CLICK ON THIS WEBSITE
HOW TO ADD
BACK TO THE MENU
CLICK ON THIS WEBSITE
INPUT #'S TO ADD
BACK TO THE MENU
CLICK ON THIS WEBSITE
Internal Link
BACK TO THE MENU
CLICK ON THIS WEBSITE
10 COMMANDENTS
BACK TO THE MENU
CLICK ON THIS WEBSITE
TO SEE CGI CODE
BACK TO THE MENU
CLICK ON THIS WEBSITE
JavaScript Search
BACK TO THE MENU
CLICK ON THIS WEBSITE
Java Servlet
Java Program
BACK TO THE MENU
(This is the end of the page.)