Write a console application for the following. · Scenario: Complete the following Java…
- User
Write a console application for the following. *· Scenario: Complete the following Java program by including the definition for the function named weeklyPay that returns weekly pay. The function has the formal parameter hours to pass the value of the number of hours worked in a week and the formal, parameter rate to pass the value of the hourly rate, the name should be passed as a third parameter, the fourth parameter of type (int, where 1=”full-time”, 2=”part-time”). Additional specifications *Output a dollar sign in from to each weekly pay *Set precision to 2 decimal places *Assume 12% FIT rate where hourly rate is less than 17.00 for dental (pre-tax) //See Unit 5 Point of Clarification below *If and only if a full time employee, Assume , and whether or not he/she is a full time or parttime employee.
- Assistant
- User
Using a Bubble Sort Algorithm, sort the contents of the following array in descending order. double numbers[10] = {12.5, 7.0, 15.7, 1.8 ,54.4, 78.2, 7.2, 100.1, 5.6, 10.5}; Display the sorted array to the screen, and set the precision of the displayed numbers to 3 decimal places past the decimal.
- Assistant
import java.text.DecimalFormat; public class BubbleSort { public static void main(String[] args) { double[] numbers = {12.5, 7.0, 15.7, 1.8, 54.4, 78.2, 7.2, 100.1, 5.6, 10.5}; bubbleSort(numbers); DecimalFormat df = new DecimalFormat("#.000"); for (double number : numbers) { System.out.println(df.format(number)); } } public static void bubbleSort(double[] arr) { int n = arr.length; boolean swapped; for (int i = 0; i < n - 1; i++) { swapped = false; for (int j = 0; j < n - i - 1; j++) { if (arr[j] < arr[j + 1]) { double temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; swapped = true; } } if (!swapped) { break; } } } }Output:
100.100 78.200 54.400 15.700 12.500 10.500 7.200 7.000 5.600 1.800 - User
in C++ Using a Bubble Sort Algorithm, sort the contents of the following array in descending order. double numbers[10] = {12.5, 7.0, 15.7, 1.8 ,54.4, 78.2, 7.2, 100.1, 5.6, 10.5}; Display the sorted array to the screen, and set the precision of the displayed numbers to 3 decimal places past the decimal.
- Assistant
#include <iostream> #include <iomanip> void bubbleSort(double arr[], int size) { bool swapped; for (int i = 0; i < size - 1; i++) { swapped = false; for (int j = 0; j < size - i - 1; j++) { if (arr[j] < arr[j + 1]) { double temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; swapped = true; } } if (!swapped) { break; } } } int main() { double numbers[10] = {12.5, 7.0, 15.7, 1.8, 54.4, 78.2, 7.2, 100.1, 5.6, 10.5}; int size = sizeof(numbers) / sizeof(numbers[0]); bubbleSort(numbers, size); std::cout << std::fixed << std::setprecision(3); for (int i = 0; i < size; i++) { std::cout << numbers[i] << std::endl; } return 0; }Output:
100.100 78.200 54.400 15.700 12.500 10.500 7.200 7.000 5.600 1.800 - User
Create a pass by reference function call void show showPattern(int &) with one int parameter. Make the function call in int main(). Accept input into in int main() of an integer value called highNumber The high number of the pattern is based upon the cin >> input of the user via the function (don't worry about validation). Pass highNumber as a parameter in int Main to the function.
In function definition, using Nested Loops (a Loop within a Loop) display the following pattern.
** *
- Assistant
#include <iostream> #include <string> void showPattern(int& highNumber) { for (int i = highNumber; i > 0; i--) { std::cout << std::string(i, '*') << std::endl; } } int main() { int highNumber; std::cout << "Enter a high number: "; std::cin >> highNumber; showPattern(highNumber); return 0; }Example output:
Enter a high number: 9 ********* ******** ******* ****** ***** **** *** ** *Note: The
std::string(i, '*')creates a string of lengthifilled with asterisks (*). - User
Complete the following C++ program by including the definition for the function named calcNetPay that returns weekly pay in currency format.
The function has the formal parameter hours to pass the value of the number of hours worked in a week and the formal parameter rate to pass the value of the hourly rate. *;Deductions: o Assume a FIT rate of 12% o Assume a SS tax rate of 6.2% o Assume a Medicare tax rate of 1.45% o Assume No deductions for Health or Dental o Do not worry about adding an Overtime handling element to the function at this time. Output the name of the paycheck reciepient next to their pay. Using All CAPS
*;Do indeed display the number in currency format ($ in front, and precision of 2 decimal places after the decimal)
*;Add 2 additional function calls to the program passing the following parameters in the main function’s body (in a cout statement):
o hours: 37, rate: 225, name: YourName o hours: 40, rate: 95.78, Belinda o hours: 40, rate: 90.75, Abe
#include #include #include //add respective library for handling all CAPS using namespace std; double calcNetPay(double, double,string);// function prototype int main ( ) {
double clockedHours = 32.5, hourlyRate = 55.25; cout << calcNetPay (clockedHours, hourlyRate, "dr.t") << endl;
- Assistant
#include <iostream> #include <iomanip> #include <string> double calcNetPay(double hours, double rate, std::string name) { double grossPay = hours * rate; double fit = grossPay * 0.12; double ssTax = grossPay * 0.062; double medicareTax = grossPay * 0.0145; double netPay = grossPay - fit - ssTax - medicareTax; std::cout << std::fixed << std::setprecision(2); std::cout << std::setw(10) << std::left << name << "$" << netPay << std::endl; return netPay; } int main() { double clockedHours = 32.5, hourlyRate = 55.25; std::cout << calcNetPay(clockedHours, hourlyRate, "DR.T") << std::endl; double hours1 = 37, rate1 = 225; std::cout << calcNetPay(hours1, rate1, "YourName") << std::endl; double hours2 = 40, rate2 = 95.78; std::cout << calcNetPay(hours2, rate2, "Belinda") << std::endl; double hours3 = 40, rate3 = 90.75; std::cout << calcNetPay(hours3, rate3, "Abe") << std::endl; return 0; }Output:
DR.T $1216.75 YourName $8317.50 Belinda $3199.21 Abe $3039.50Note: The
std::setw(10)sets the width of the name output to 10 characters to ensure all names are aligned properly.