Assignment_4_Solution

advertisement
‫المملكة العربية السعودية‬
‫وزارة التعليم العالي‬
‫جامعة المجمعة‬
‫كلية علوم الحاسب وتقنية المعلومات‬
Kingdom of Saudi Arabia
Ministry of Higher Education
Majmaah University
Computer Science and Information Technology College
Assignment 4
Write a complete C++ program that reads number of employees, then initialize an array to
store employee's salaries. Your program should reads the salaries from the user then add 250
as a bounce for salaries less than 5000 Saudi Riyal .
Example of the output
Enter the number of employees: 4
Enter their salaries: 6000 3500 10000 2000
The salaries after updating: 6000 3750 10000 2250
Solution:
#include <iostream>
using namespace std;
void main()
{
int num;
cout<<"Enter the number of employees:";
cin>>num;
int *salary= new int [num]; // This is the way to how let user to determine array size
cout<<"Enter their salaries";
for (int i=0 ; i < num ; i++)
{
cin>>salary[i];
if (salary[i] < 5000)
salary[i]+= 250;
}
cout<<"The salaries after updating: ";
for (int i=0 ; i < num ; i++)
cout<<salary[i]<<" ";
}
1
Related documents
Download