Create a pass by reference function call void displayPattern(int &) with one int…
- User
Create a pass by reference function call void displayPattern(int &) with one int parameter. Make the function call in int main(). Accept input into in int main() of an integeger 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
Here is the code that satisfies the given requirements:
#include <iostream> void displayPattern(int& highNumber) { for (int i = highNumber; i >= 1; i--) { for (int j = 1; j <= i; j++) { std::cout << "*"; } std::cout << std::endl; } } int main() { int highNumber; std::cout << "Enter a high number: "; std::cin >> highNumber; displayPattern(highNumber); return 0; }In this code, we define the
displayPatternfunction that accepts a reference to anintparameterhighNumber. Within the function, we use nested loops to print the pattern. The outer loop controls the number of rows and the inner loop prints the asterisks in each row. The number of asterisks in each row is decremented by one in each iteration of the outer loop. In themainfunction, we prompt the user to enter a value forhighNumberand then pass it as a parameter to thedisplayPatternfunction. - User
Using a Bubble Sort Algorithm, sort the contents of the following array in descending order. double numbers[7] = {23.6, 46.7, 12.7, 35.1,54.88,78.7,100.5}; Display the sorted array to the screen, and set the precision of the displayed numbers to 3 decimal places past the decimal.
- Assistant
Here is the code that sorts the contents of the given array in descending order using the Bubble Sort algorithm and displays the sorted array with 3 decimal places of precision:
#include <iostream> #include <iomanip> void bubbleSort(double numbers[], int size) { for (int i = 0; i < size - 1; i++) { for (int j = 0; j < size - i - 1; j++) { if (numbers[j] < numbers[j + 1]) { double temp = numbers[j]; numbers[j] = numbers[j + 1]; numbers[j + 1] = temp; } } } } int main() { double numbers[7] = {23.6, 46.7, 12.7, 35.1, 54.88, 78.7, 100.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::cout << std::endl; return 0; } - User
Your friend, John is used to text message communication thus when he types “I” he types it as so i …
Write a C++ program that will take John’s sentence as follows in as a string, and output instances of uppercase “I” if an instance of lowercase “i” is found in the string. The resulting string should contain the corrected instances. In all other instances, else leave the character in the case that it originally was.
The input string is: “Yesterday’s Dr. House broadcast was excellent! i am so happy! i can only wonder what House can next do.”
/*Recall that a string is an Array of Characters. Think of the built in function that enables one to capitalize a character. */
- Assistant
Here is the code that takes John's sentence as input, checks for lowercase "i" in the string, and replaces it with uppercase "I" if found:
#include <iostream> #include <string> std::string correctSentence(const std::string& sentence) { std::string correctedSentence = sentence; for (int i = 0; i < correctedSentence.length(); i++) { if (correctedSentence[i] == 'i') { correctedSentence[i] = 'I'; } } return correctedSentence; } int main() { std::string sentence = "Yesterday’s Dr. House broadcast was excellent! i am so happy! i can only wonder what House can next do."; std::string correctedSentence = correctSentence(sentence); std::cout << correctedSentence << std::endl; return 0; }In this code, we define the
correctSentencefunction that accepts a constant reference to astd::stringparametersentence. Inside the function, we create a copy of thesentencecalled . We then iterate over each character in and check if it is a lowercase "i". If found, we replace it with an uppercase "I". Finally, we return the corrected string. - 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 10% 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: 39, rate: 125, name: YourName o hours: 39, rate: 65.78, Caleb o hours: 39, rate: 75.75, Alejandra
#include #include #include //add respective library for handling all CAPS using namespace std; double getNetPay(double, double,string);// function prototype int main ( ) {
double clockedHours = 32.5, hourlyRate = 55.25; cout << getNetPay (clockedHours, hourlyRate, "dr.t") << endl;
- Assistant
Here is the complete program with the definition for the function
getNetPay:#include <iostream> #include <iomanip> #include <string> using namespace std; double getNetPay(double hours, double rate, string name); int main() { double clockedHours = 32.5, hourlyRate = 55.25; cout << getNetPay(clockedHours, hourlyRate, "DR.T") << endl; cout << "Additional function calls: " << endl; cout << getNetPay(39, 125, "YourName") << endl; cout << getNetPay(39, 65.78, "Caleb") << endl; cout << getNetPay(39, 75.75, "Alejandra") << endl; system("pause"); return 0; } double getNetPay(double hours, double rate, string name) { double grossPay = hours * rate; double fitRate = 0.1; double ssTaxRate = 0.062; double medicareTaxRate = 0.0145; double deductions = grossPay * (fitRate + ssTaxRate + medicareTaxRate); double netPay = grossPay - deductions; cout << name << ": $" << fixed << setprecision(2) << netPay << endl; return netPay; } - User
OPERATIONALIZE THIS EXCEL SPREADSHEET WITH C++ -TCC COSTS
https://www.dropbox.com/s/zo2mg5ptk138t3n/TCC_Costs_McMillan.xlsx?dl=0 Links to an external site.
Folder/CPP: TCC_Cost_Yourlastname
Upload the file (cpp or .zip of your entire solution) via the browse button below, prior to the end of the exam. The code should work when extracted and/or run. Be sure to provide a working error-free program.
- Assistant
I'm sorry, but I cannot access or download files from external websites. However, I can provide guidance on how to operationalize the Excel spreadsheet with C++.
To operationalize the Excel spreadsheet with C++, you would need to extract the relevant data from the spreadsheet and write code to perform the required calculations and operations.
Here is a general outline of the steps you can follow:
-
Install a C++ library that allows you to read and manipulate Excel files, such as "libxlsxwriter" or "libxl".
-
Include the necessary header files for the Excel library in your C++ code.
-
Open the Excel file in your C++ code using the appropriate functions provided by the library.
-
Access the specific worksheet and cells containing the TCC costs data using the library's functions.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.