Q3 Lab 5
unknown
c_cpp
3 years ago
1.6 kB
7
Indexable
#include <iostream> //question 1 #include <queue> #include <string> using namespace std; struct record { string name; float salary; int service; }; void update(queue<record> *staff, string name,queue<record> temporary) { float tempsalary; cout<<"Enter new salary: "; cin >> tempsalary; while(!(*staff).empty()) { if((*staff).front().name ==name) { (*staff).front().salary = tempsalary; } temporary.push((*staff).front()); (*staff).pop(); } (*staff).swap(temporary); } void display(queue<record>staff) { int i=1; while(!staff.empty()) { cout <<endl; cout<<i <<". Staff Name: " << staff.front().name << ", Salary: "<< staff.front().salary<< ", Year of Service: " << staff.front().service; staff.pop(); i++; } } int main(int argc, char **argv) { string name [] = {"Ahmad","Siew May","Ravi","John","Mohammad","Jennifer"}; float salary [] = {12000.0, 4800.0,6000.0, 5500.0, 14000.0, 11000.0}; int service [] = {10,4,12,7,6,5}; string nama; queue <record> staff; queue<record>temp; //Question (2) for(int i=0; i<6;i++) { record n; n.name=name[i]; n.salary=salary[i]; n.service=service[i]; staff.push(n); } cout<<"\n # Menu : Update Salary # "<<endl; cout<<" Enter name : "; getline(cin, nama); update(&staff,nama,temp); display(staff); cout<<"\nEnd of program"; return 0; return 0; }
Editor is loading...