Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

donations.cpp // This program shows the donations made to the United Cause // by the employees of CK Graphics, Inc. It displays // the donations

image text in transcribed

donations.cpp

// This program shows the donations made to the United Cause

// by the employees of CK Graphics, Inc. It displays

// the donations in order from lowest to highest

// and in the original order they were received.

#include

using namespace std;

// Function prototypes

void arrSort(int *[], int);

void showArray(const int [], int);

void showArrPtr(int *[], int);

int main()

{

const int NUM_DONATIONS = 15; // Number of donations

// An array containing the donation amounts.

int donations[NUM_DONATIONS] = { 5, 100, 5, 25, 10,

5, 25, 5, 5, 100,

10, 15, 10, 5, 10 };

// An array of pointers to int.

int *arrPtr[NUM_DONATIONS] = { nullptr, nullptr, /*write your code here*/ };

// Each element of arrPtr is a pointer to int. Make each

// element point to an element in the donations array.

/* Write your code here*/

// Sort the elements of the array of pointers.

arrSort(arrPtr, NUM_DONATIONS);

// Display the donations using the array of pointers. This

// will display them in sorted order.

cout

showArrPtr(arrPtr, /*Write your code here*/);

// Display the donations in their original order.

cout

showArray(donations, /*Write your code here*/);

return 0;

}

void arrSort(int *arr[], int size)

{

int startScan, minIndex;

int *minElem;

for (startScan = 0; startScan

{

minIndex = startScan;

minElem = arr[startScan];

for(int index = startScan + 1; index

{

if (*(arr[index])

{

minElem = arr[index];

minIndex = index;

}

}

arr[minIndex] = arr[startScan];

arr[startScan] = minElem;

}

}

// Definition of function showArray.

//This function displays the contents of arr.

void showArray(const int arr[], int size)

{

/* Write your code here */

}

// Definition of function showArrPtr.

//This function displays the contents of the array pointed to by arr.

void showArrPtr(int *arr[], int size)

{

/* Write your code here */

}

image text in transcribed

image text in transcribed

image text in transcribed

currency.cpp

// This program lets the user enter a number. The

// dollarFormat function formats the number as

// a dollar amount.

#include

#include

using namespace std;

// Function prototype

void dollarFormat(string &);

int main ()

{

string input;

// Get the dollar amount from the user.

cout

cin >> input;

dollarFormat(input);

cout

cout

return 0;

}

//************************************************************

// Definition of the dollarFormat function. This function *

// accepts a string reference object, which is assumed to *

// to hold a number with a decimal point. The function *

// formats the number as a dollar amount with commas and *

// a $ symbol. *

//************************************************************

void dollarFormat(string ?)

{

/* Write your code here */

}

Problem 1: 30 The Relief Cause, a charitable relief agency, solicits donations from businesses. The local office received the following donations from the employees of UWGB: $5, $100, $5, $25, $10, $5, $25, $5, $5, $100, $10, $15, $10, $5, $10, $25, $45, $15 The donations were received in the order they appear. The relief agency's manager has asked you to write a program that displays the donations in ascending order, as well as in their original order. For this program, use the supplied code in donations.cpp file. The program is written with some code segments missing which you need to complete. You need to write code and finished this partially completed program and run it successfully error-free. Your code segment will go in place where you see the following text /* Write your code here*/ Any place within the file you this text, this means you have to include code that will perform the required function(s) mentioned in the preceding comment(s). You also need to complete to functions (showArray, and showArrPtr) whose prototypes are declare in the file. The output of the completed program will be like the following: The donations, sorted in ascending order are: 5 5 5 5 5 5 5 10 10 10 10 10 15 15 25 25 25 45 100 100 The donations, in their original order are: 5 100 5 25 10 5 25 5 5 100 10 15 10 5 10 5 10 25 45 15 Problem 2: 40 Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should perform the following steps: Ask the user how many students were surveyed. An array of integers with this many elements should then be dynamically allocated. Allow the user to enter the number of movies each student saw into the array. Calculate and display the average, median, and mode of the values entered. . O In statistics, when a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average, of the two middle values. The function should determine the median of the array. This value should be returned as a double. In statistics, the mode of a set of values is the value that occurs most often or with the greatest frequency. Your function should determine the mode of the array. That is, it should determine which value in the array occurs most often. The mode is the value the function should return. If the array has no mode (none of the values occur more than once), the function should return -1 and mode is unavailable. You need to use pointer notation instead of array notation. Input Validation: Do not accept negative numbers for input. Problem 3: 30 As programmer, the local retail store asked you to develop a function named formatDollar that inserts commas and a $ sign at appropriate locations in a string object containing an unformatted dollar amount. As an argument, the function should accept a reference to a string object. You may assume the string object contains a value such as 1084567.89. The function should modify the string object so it contains a formatted dollar such as $1,084,567.89. Similarly 425389.35 will be formatted as $425,389.35. For this problem, use the supplied currency.cpp file and modify/insert your code to complete the task and generate the following output Enter a dollar amount in the form nnnnn.nn : 45879357.322 Here is the amount formatted: $45,879,357.322 Hint: Use string class find () method to find the occurrence of the decimal point

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

ISBN: 1638280428, 978-1638280422

More Books

Students also viewed these Databases questions