#include <iostream>
using namespace std;
const int SIZE=30;
const int SIZE2=1;
struct Speaker
{
char name[SIZE];
int phoneNo;
char topic[SIZE];
double fee;
};
int main()
{
Speaker s[SIZE2];
int choice,spNum,choice2;
char searchTopic[SIZE];
char *strPtr;
int i;
do
{
cout<<"Speakers' Bureau"<<endl;
cout<<"***********************"<<endl;
cout<<"1. New speaker registration"<<endl;
cout<<"2. Change data"<<endl;
cout<<"3. Display data"<<endl;
cout<<"4. Search data"<<endl;
cout<<"5. Quit"<<endl<<endl;
cout<<"Enter your choice: ";
cin>>choice;
cout<<endl;
switch(choice)
{
case 1: for(i=0;i<SIZE2;i++)
{
cout<<"Speaker #"<<i+1<<endl;
cout<<"Enter name: ";
cin.ignore();
cin.getline(s[i].name,SIZE);
cout<<"Enter telephone number: ";
cin>>s[i].phoneNo;
cout<<"Enter speaking topic: ";
cin.ignore();
cin.getline(s[i].topic,SIZE);
cout<<"Enter fee: ";
cin>>s[i].fee;
while((s[i].fee)<0)
{
cout<<"Please do not enter negative values!!"<<endl;
cout<<"Enter fee: ";
cin>>s[i].fee;
}
cout<<endl;
}
break;
case 2: cout<<"Enter the account number: ";
cin>>spNum;
cout<<"Which of the following data you want to change?"<<endl;
cout<<"1. Name"<<endl;
cout<<"2. Telephone Number"<<endl;
cout<<"3. Speaking Topic"<<endl;
cout<<"4. Fee"<<endl;
cout<<"Enter your choice: ";
cin>>choice2;
if(choice2==1)
{
cout<<"Enter new name: ";
cin.ignore();
cin.getline(s[spNum-1].name,SIZE);
}
else if(choice2==2)
{
cout<<"Enter new telephone number: ";
cin.ignore();
cin>>s[spNum-1].phoneNo;
}
else if(choice2==3)
{
cout<<"Enter new topic: ";
cin.ignore();
cin.getline(s[spNum-1].topic,SIZE);
}
else if(choice2==4)
{
cout<<"Enter new fee: ";
cin.ignore();
cin>>s[spNum-1].fee;
while(s[spNum-1].fee<0)
{
cout<<"Please do not enter negative values!!"<<endl;
cout<<"Enter fee: ";
cin.ignore();
cin>>s[spNum-1].fee;
}
}
break;
case 3: for(i=0;i<SIZE2;i++)
{
cout<<"Speaker #"<<i+1<<endl;
cout<<"Name : "<<s[i].name<<endl;
cout<<"Telephone : "<<s[i].phoneNo<<endl;
cout<<"Speaking Topic : "<<s[i].topic<<endl;
cout<<"Fee : "<<s[i].fee<<endl<<endl;
}
break;
case 4: cout<<"Enter the speaker's topic you want to search: ";
cin.ignore();
cin.getline(searchTopic,SIZE);
for(i=0;i<SIZE2;i++)
{
strPtr=strstr(s[i].topic,searchTopic);
if(strPtr!=NULL)
break;
}
if(strPtr!=NULL)
cout<<s[i].topic<<endl<<endl;
else
cout<<"No topic was found"<<endl<<endl;
break;
default:cout<<"You are exiting the system"<<endl;
}
}while(choice!=5);
system("pause");
return 0;
}
just for case 4 in switch, I would like to use function instead of write it into main. The function should accept part of the customer's name as an argument. Can someone help me?

New Topic/Question
Reply



MultiQuote




|