I need help with writing a program that will allow me lookup and a search for a
ID: 3743216 • Letter: I
Question
I need help with writing a program that will allow me lookup and a search for a users address, name, date of birth, finincal inofrmation and more. This will allow me to look at all the information the useser has enter. I also want to add a filter so I can search for information by a specific category. when I open the txt file. Can you show your code and print the out put. I want to be able to use this program on macs and windows. I want this in c++ and GUI. I am using xcode, but if you dont have xcode then you can use any program that you have to write the code. Thanks alot
Explanation / Answer
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
class recser
{
public: //variable declaration
string s1[15],s2[15],s3[100],s4[15],s5[15];
int k=0;
string a3,b3,c4,d3,e3;
void student()
{
int i;
k=0; //importaing data from filr to array
fstream myfile("C:\Student.txt", std::ios_base::in);
while (myfile >> a3 >> b3 >> c4 >> d3 >> e3 )
{
s1[k]=a3;
s2[k]=b3;
s3[k]=c4;
s4[k]=d3;
s5[k]=e3;
k=k+1;
}
int ch,pos,t;
string se;
do{
pos=0;
t=0;
se="";
cout<<" "; //menu for the user
cout<<"Welcome to Search Portal for Users"<<endl;
cout<<"1.Display all user details."<<endl;
cout<<"2.Search by First Name."<<endl;
cout<<"3.Search by Last Name."<<endl;
cout<<"4.Search by Address."<<endl;
cout<<"5.Search by Designation."<<endl;
cout<<"6.Search by Office Name."<<endl;
cout<<"7.Exit."<<endl;
cout<<"Enter your choice"<<endl;
cin>>ch;
if(ch==1) //displaying all result
{
cout<<" ";
cout<<"Fname"<<" "<<"Lname"<<" "<<"Address"<<" "<<"Designation"<<" "<<"Company"<<endl;
for(i=0;i<k;i++)
{
cout<<s1[i]<<" "<<s2[i]<<" "<<s3[i]<<" "<<s4[i]<<" "<<s5[i]<<endl;
}
}
if(ch==2) //displaying result based on first name search
{
se="";
cout<<" ";
cout<<"Enter the First name to search"<<endl;
cin>>se;
for(i=0;i<k;i++)
{
if(s1[i]==se)
{
pos=i;
t=1;
break;
}
}
if(t==1)
{
cout<<" ";
cout<<"First Name : "<<s1[pos]<<endl;
cout<<"Last Name : "<<s2[pos]<<endl;
cout<<"Address : "<<s3[pos]<<endl;
cout<<"Designation : "<<s4[pos]<<endl;
cout<<"Company : "<<s5[pos]<<endl;
}
else
cout<<"Match not found"<<endl;
}
if(ch==3)//displaying result based on last name search
{
se="";
cout<<" ";
cout<<"Enter the Last name to search"<<endl;
cin>>se;
for(i=0;i<k;i++)
{
if(s2[i]==se)
{
pos=i;
t=1;
break;
}
}
if(t==1)
{
cout<<" ";
cout<<"First Name : "<<s1[pos]<<endl;
cout<<"Last Name : "<<s2[pos]<<endl;
cout<<"Address : "<<s3[pos]<<endl;
cout<<"Designation : "<<s4[pos]<<endl;
cout<<"Company : "<<s5[pos]<<endl;
}
else
cout<<"Match not found"<<endl;
}
if(ch==4)//displaying result based on address search
{
se="";
cout<<" ";
cout<<"Enter the Address to search"<<endl;
cin>>se;
for(i=0;i<k;i++)
{
if(s3[i]==se)
{
pos=i;
t=1;
break;
}
}
if(t==1)
{
cout<<" ";
cout<<"First Name : "<<s1[pos]<<endl;
cout<<"Last Name : "<<s2[pos]<<endl;
cout<<"Address : "<<s3[pos]<<endl;
cout<<"Designation : "<<s4[pos]<<endl;
cout<<"Company : "<<s5[pos]<<endl;
}
else
cout<<"Match not found"<<endl;
}
if(ch==5) //displaying result based on Designation search
{
se="";
cout<<" ";
cout<<"Enter the Designation to search"<<endl;
cin>>se;
for(i=0;i<k;i++)
{
if(s4[i]==se)
{
pos=i;
t=1;
break;
}
}
if(t==1)
{
cout<<" ";
cout<<"First Name : "<<s1[pos]<<endl;
cout<<"Last Name : "<<s2[pos]<<endl;
cout<<"Address : "<<s3[pos]<<endl;
cout<<"Designation : "<<s4[pos]<<endl;
cout<<"Company : "<<s5[pos]<<endl;
}
else
cout<<"Match not found"<<endl;
}
if(ch==6)//displaying result based on office name search
{
se="";
cout<<" ";
cout<<"Enter the Company to search"<<endl;
cin>>se;
for(i=0;i<k;i++)
{
if(s5[i]==se)
{
pos=i;
t=1;
break;
}
}
if(t==1)
{
cout<<" ";
cout<<"First Name : "<<s1[pos]<<endl;
cout<<"Last Name : "<<s2[pos]<<endl;
cout<<"Address : "<<s3[pos]<<endl;
cout<<"Designation : "<<s4[pos]<<endl;
cout<<"Company : "<<s5[pos]<<endl;
}
else
cout<<"Match not found"<<endl;
}
if(ch==7)
break;
}while(ch!=7);
}
};
int main() //main function
{
recser obj; //object of the class
obj.student(); //calling the function
return 0;
}