[DS 25] Lab 8 - Hashtable
[DS 25] Lab 8 - Hashtable
1
AGENDA
Letter Counter
Write a program that:
▪ When given a string of letters, find frequencies of
individual chars.
▪Input : str = “helloworld";
▪Output : Frequencies of individual letters are (h, 1) (e, 1)
(l, 3) (o, 2) (w, 1) (r, 1) (d, 1)
void main()
{
unordered_map<char, int> wordCounter;
string sentence = "";
cout << "Enter a sentence: ";
cin >> sentence;
▪ Press_2: To upgrade the salary of all the employees who had been
employed by the company for 10 years or more by a given increase rate.
The user should enter the increase rate. Print names and new salaries.
void Upgrade(float increase)
Employee e1(123,"Mohamed",3200,2005);
Employee e2(234,"Nour",5600,2010);
Employee e3(345,"Meena",8900,2008);
employees[e1.id]=e1;
employees[e2.id]=e2;
employees[e3.id]=e3;
int choice;
cout << "To Update An Employee: Press 1" << endl <<
"Upgrade All The Employees: Press 2" << endl;
cin >> choice;
switch (choice)
{
case 1:
{ int ID;
double Sal;
cout << "Enter ID and New Salary to Update
Employee Salary" << endl;
cin >> ID >> Sal;
employees[ID].updateSalary(Sal);
cout << employees[ID].name << " " <<
employees[ID].salary;
break;}
case 2:
{ double increaseRate;
cout << "Enter The Increase Rate" << endl;
cin >> increaseRate;
for (auto it = employees.begin();it !=
employees.end();it++)
{ (*it).second.upgrade(10);
cout << (*it).second.name << " " <<
(*it).second.salary << endl;
}}
15