In a company an employee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the employee's salary is input by the user write a program to find his gross salary.
Develop a code for the hybrid Inheritance diagram given below
· The employee details class consisting of data members such as name and emp_id.
· The normal pay class consisting of data members such as basic salary.
· The additional pay class consisting of data members such as hours, rupees and additional pay.
· The net pay class consisting of member function cal() to find the employee total salary = additional pay + basic salary.
(Reusability using inheritance)
Runtime Input :
Rajesh
1101
10000
10
50
Output :
Rajesh
1101
10000
10
50
500
10500
Test #1: Find the bug
#include <iostream>
#include <vector>
std::vector<std::string> getUniqueBrands(const std::vector<std::string>& brand1, const std::vector<std::string>& brand2)
{
throw std::logic_error("yet to be implemented");
}
int main()
{
std::vector<std::string> brand1 = {"LOUIS_VUITTON", "HERMES", "PRADA"};
std::vector<std::string> brand2 = {"GUCCI", "PRADA", "HERMES"};
std::vector<std::string> result = getUniqueBrands(brand1, brand2);
for(auto element : result)
{
std::cout << element << ' ';
// should print GUCCI HERMES LOUIS_VUITTON PRADA
}
}
Test #3:
1. Create a matrix of size n x n, where n is the user input. 2. Populate the matrix with random integers (without taking user input). 3. Print the diagonal elements of the matrix from top left to bottom right corner.
Mean, Median and Mode
Given a list of integers, write a program to print the mean, median and mode.
Mean - The average value of all the numbers.
Median - The mid point value in the sorted list.
Mode - The most common value in the list. If multiple elements with same frequency are present, print all the values with same frequency.
Input
The input will be a single line containing space-separated integers.
Output
The first line of output should contain the mean, round off the value to 2 decimal places.
The second line of output should contain the median, round off the value to 2 decimal places.
The third line of output should contain the mode.
See Sample Input/Output for the output format.
Explanation
as the length of the list is an odd number, the median will be the middle number in
Mean: 5.45
Median: 3
Mode: 2 3
Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
Sample Output 1
Mean: 4.67
Median: 4.5
Mode: 2
Sample Input 2
2 6 3 1 8 12 2 9 10 3 4
Sample Output 2
Mean: 5.45
Median: 3
Mode: 2 3Shift Numbers - 2
Given a string, write a program to move all the numbers in it to its start.
Input
The input will contain a string A.
Output
The output should contain a string after moving all the numbers in it to its start.
Explanation
For example, if the given string A is "1good23morning456", the output should be "123456goodmorning", as it contains numbers at the start.
Sample Input 1
1good23morning456
Sample Output 1
123456goodmorning
Sample Input 2
com876binat25ion
Sample Output 2
87625combination
Sum of Prime Numbers In the Input
Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.
Note: One is neither prime nor composite number.
Input
The input will be a single line containing space-separated integers..
Output
The output should be a single line containing the sum of all prime numbers from 1 to N.
Explanation
For example, if the given list of integers are
2 4 5 6 7 3 8
As 2, 3, 5 and 7 are prime numbers, your code should print the sum of these numbers. So the output should be 17.
Sample Input 1
2 4 5 6 7 3 8
Sample Output 1
17
Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
31
Sum of Prime Numbers from M to N
Given two integers M and N, write a program to print the sum of prime numbers from M to N.
Input
The first line of input will contain a positive integer (M).
The second line of input will contain a positive integer (N).
Output
The output should be a single line containing the sum of prime numbers from M to N.
Explanation
For example, if the given M and N are 5 and 11, as all the prime numbers from 5 to 11 are 5, 7, and 11. So the output should be sum of these primes (5+7+11), which is 23.
Similarly, if the given numbers are M is 18 and N is 40, as all the prime numbers from 18 to 40 are 19, 23, 29, 31,and 37. So the output should be sum of these primes (19+23+29+31+37), which is 139.
Sample Input 1
5
11
Sample Output 1
23
Sample Input 2
18
40
Sample Output 2
139
Index of Last Occurrence
Write a program to print the index of the last occurrence of the given number N in the list.
Input
The first line of input will contain space-separated integers.
The second line of input will contain an integer N.
Output
The output should be the index of the last occurrence of the number N.
Explanation
For example, if the given list of numbers and N are
2 4 5 6 7 8 2 4 5 2 3 8
2
Number 2 present at index locations 0, 6, 9, as the last occurrence, is at index 9. So the output should be 9.
Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
2
Sample Output 1
9
Sample Input 2
65 87 96 31 32 86 57 69 20 42 32 32
32
Sample Output 2
11
Mean, Median and Mode
Given a list of integers, write a program to print the mean, median and mode.
Mean - The average value of all the numbers.
Median - The mid point value in the sorted list.
Mode - The most common value in the list. If multiple elements with same frequency are present, print all the values with same frequency.Input
The input will be a single line containing space-separated integers.Output
The first line of output should contain the mean, round off the value to 2 decimal places.
The second line of output should contain the median, round off the value to 2 decimal places.
The third line of output should contain the mode.
See Sample Input/Output for the output format.Explanation
For example, if the given list of integers are
2 4 5 6 7 8 2 4 5 2 3 8The average of all the numbers is 4.67.
After sorting the array,
2 2 2 3 4 4 5 5 6 7 8 8Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
Sample Output 1
Mean: 4.67
Median: 4.5
Mode: 2
Index of Last Occurrence
Write a program to print the index of the last occurrence of the given number N in the list.Input
The first line of input will contain space-separated integers.
The second line of input will contain an integer N.Output
The output should be the index of the last occurrence of the number N.Explanation
For example, if the given list of numbers and N are
2 4 5 6 7 8 2 4 5 2 3 8
2Number 2 present at index locations 0, 6, 9, as the last occurrence, is at index 9. So the output should be 9.
Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
2
Sample Output 1
9
Sample Input 2
65 87 96 31 32 86 57 69 20 42 32 32
32