hi, I want to write a program in C++ that search for the letters :A , D , U , I
ID: 3610685 • Letter: H
Question
hi, I want to write a program in C++ that search for the letters :A , D , U , I , N and T ( or t ) and then display the message"Letter found = = --- " the program searches for the letter in the command line ,which can contain an infinite amount of parameters, the programmust treat the command line as a string in order to find theletters. pleas I need the code with explainations . . . hi, I want to write a program in C++ that search for the letters :A , D , U , I , N and T ( or t ) and then display the message"Letter found = = --- " the program searches for the letter in the command line ,which can contain an infinite amount of parameters, the programmust treat the command line as a string in order to find theletters. pleas I need the code with explainations . . .Explanation / Answer
#include<iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <string.h>
class Hash
{
int hval;
char h[20][20];
public:
Hash()
{
//Initializing the hash table with null strings
for(int i=0;i<13;i++)
strcpy(h[i]," ");
}
void menu()
{
cout<<endl;
cout<<"DICTIONARY FUNCTIONS"<<endl;
cout<<"====================="<<endl;
cout<<"1.Insert"<<endl;
cout<<"2.Delete"<<endl;
cout<<"3.Search"<<endl;
cout<<"4.Display"<<endl;
cout<<"5.Exit"<<endl;
}
void ins()
{
char *a;
int op;
hval=0;
cout<<"Plz enter the string"<<endl;
cin>>a;
for(int j=0;j<strlen(a);j++)
hval=hval+int(a[j]);
hval=hval%13;
if(strcmp(h[hval]," ")==0)
strcpy(h[hval],a);
else
{
cout<<"Do u want to replace thestring(Y=0/N=1)"<<endl;
cin>>op;
if(op==0)
strcpy(h[hval],a);
}
}
void del()
{
char *str;
cout<<"PLZ enter to be deleted from thedictionary"<<endl;
cin>>str;
hval=0;
for(int j=0;j<strlen(str);j++)
hval=hval+int(str[j]);
hval=hval%13;
int rval=search(str);
if(rval==-1)
cout<<"The word entered is not present in thedictionary"<<endl;
else
{
strcpy(h[rval]," ");
cout<<"The word has been successfully deleted from thedictionary"<<endl;
}
}
int search(char *str)
{
hval=0;
for(int j=0;j<strlen(str);j++)
hval=hval+int(str[j]);
hval=hval%13;
if(strcmp(h[hval],str)==0)
return hval;
else
return -1;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.