Question

In: Computer Science

This assignment covers practical aspects of this course. This assessment covers the following course learning outcomes:...

This assignment covers practical aspects of this course. This assessment covers the following course learning outcomes: CLO 2 - Apply programming concepts to computing problems CLO 3 - Examine Code for its syntax and semantic validity Case Study The assignment is based on the monthly income of Anna, a coffee shop owner in Suva. Anna’s monthly income for 2019 is given below, and you are required to write a program that will perform some manipulation actions on her monthly income records.

jan feb march april may june
$3055.00 $4512.00 $3221.50 $4899.20 $4556.00 $4787.00
jul aug sep oct nov dec
$5002.10 $5321.00 $6025.00 $7652.00 $8623.50 $7695.00

You are required to work in groups of 3 to complete this assignment. The programming concepts you are expected to use include if…else structures, loops, functions and arrays. Your program should 1. Store Anna’s monthly income values into one array. The array declaration and assignment is given below, you can copy and paste this statement into your sourcefile directly. Notice that each element of the array is Anna’s income for each respective month.

double income_arr[] = {3055.00, 4512.00, 3221.50, 4899.20, 4556.00, 4787.00, 5002.10, 5321.00, 6025.00, 7652.00, 8623.50, 7695.00};

3. Implement a function for each of the following tasks:

a. A function that will display the menu and get the user’s selection from the menu.

b. A function that finds the highest value given an array of numbers.

c. A function that finds the lowest value given an array of numbers.

d. A function that sums all the values in a given array of numbers.

e. A function that prints the elements of a given array.

f. A function that sorts the values of an array in ascending order.

g. A function that sorts the values of an array in descending order.

h. Optional: A function that copies the values of one array into another array of the same size. Hint: This can be used when you want to sort the array in ascending and descending order, since you should not change the order of the elements in the original array.

4. Use a while loop in your main function to allow the user to try different menu options until they decide to quit/exit.

5. Other tips: a. Don’t forget to add comments where necessary

b. Format your output well so that money values have the currency symbol ($)

c. Libraries you can consider:

i. iostream for input/output

ii. iomanip for formatting output where currency is displayed

iii. algorithm for sort function

Solutions

Expert Solution

// C++ program to perform operations on array

#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

// function declaration
int menu();
void highest(double arr[], int size);
void lowest(double arr[], int size);
void sum(double arr[], int size);
void display(double arr[], int size);
void sortAscending(double arr[], int size);
void sortDescending(double arr[], int size);
void copy(double arr[], int size, double copyArr[]);

int main()
{
// define the array
double income_arr[] = {3055.00, 4512.00, 3221.50, 4899.20, 4556.00, 4787.00, 5002.10, 5321.00, 6025.00, 7652.00, 8623.50, 7695.00};
int size = 12, choice;
double temp_arr[size]; // define temporary array used for sorting

// loop that continues until the user exits
do
{
choice = menu(); // display the menu and get user choice

// based on user choice, call the function to perform the operation
switch(choice)
{
case 1:
highest(income_arr, size);
break;

case 2:
lowest(income_arr, size);
break;

case 3:
sum(income_arr, size);
break;

case 4:
cout<<"Values:"<<endl;
display(income_arr, size);
break;

case 5:
copy(income_arr, size, temp_arr); // copy the array from income_arr to temp_arr
sortAscending(temp_arr, size); // sort the temp_arr
break;

case 6:
copy(income_arr, size, temp_arr); // copy the array from income_arr to temp_arr
sortDescending(temp_arr, size); // sort the temp_arr
break;
}

cout<<endl;
}while(choice != 7);

return 0;
}

// function to display menu choice, input user choice and return the choice
int menu()
{
int choice;
cout<<"1. Finds the highest value given an array of numbers"<<endl;
cout<<"2. Finds the lowest value given an array of numbers."<<endl;
cout<<"3. Sums all the values in a given array of numbers."<<endl;
cout<<"4. Prints the elements of a given array."<<endl;
cout<<"5. Sorts the values of an array in ascending order."<<endl;
cout<<"6. Sorts the values of an array in descending order."<<endl;
cout<<"7. Exit the program"<<endl;
cout<<"Enter your choice(1-7): ";
cin>>choice; // input user choice

// validate user choice and re-prompt until valid
while(choice < 1 || choice > 7)
{
cout<<"Invalid choice. Re-enter: ";
cin>>choice;
}

return choice;
}

// function to determine and display the highest element of input array
void highest(double arr[], int size)
{
double maxEl = arr[0]; // initialize the first element to be the highest
// loop over the array to find the highest element
for(int i=1;i<size;i++)
{
if(maxEl < arr[i])
maxEl = arr[i];
}

// display the highest element
cout<<"Highest value: $"<<fixed<<setprecision(2)<<maxEl<<endl;
}

// function to determine and display the lowest element of input array
void lowest(double arr[], int size)
{
double minEl = arr[0]; // initialize the first element to be the lowest
// loop over the array to determine the lowest element
for(int i=1;i<size;i++)
{
if(minEl > arr[i])
minEl = arr[i];
}

// display the lowest element
cout<<"Lowest value: $"<<fixed<<setprecision(2)<<minEl<<endl;
}

// function to determine and total of all elements of input array
void sum(double arr[], int size)
{
double total = 0; // initialize total to 0
// loop over the array to add each element of array to total
for(int i=0;i<size;i++)
total += arr[i];

// display the total of all values
cout<<"Total of all values: $"<<fixed<<setprecision(2)<<total<<endl;
}

// function to display all the elements of input array
void display(double arr[], int size)
{
// loop over the array displaying the elements of the array
for(int i=0;i<size;i++)
{
cout<<fixed<<setprecision(2)<<"$"<<arr[i]<<" ";
}
cout<<endl;
}

// function to sort the array in ascending order
void sortAscending(double arr[], int size)
{
sort(arr, arr+size); // sort the values in ascending order
// display the sorted array
cout<<"Ascending sorted values: "<<endl;
display(arr, size);
}

// function to sort the array in descending order
void sortDescending(double arr[], int size)
{
sort(arr, arr+size, greater<double>()); // sort the values in descending order
// display the sorted array
cout<<"Descending sorted values: "<<endl;
display(arr, size);
}

// function to copy the values of arr into copyArr
void copy(double arr[], int size, double copyArr[])
{
// loop over the array copying the elements of arr into copyArr
for(int i=0;i<size;i++)
copyArr[i] = arr[i];
}

//end of program

Output:


Related Solutions

The Assignment`s learning Outcomes: In the second assignment for the Quality Management course, the students are...
The Assignment`s learning Outcomes: In the second assignment for the Quality Management course, the students are required to read the “ Nestlé Waters Unifying real-time visibility across 26 factories” case study , and answer the related questions, upon successful completion of the assignment the student should be able to: 1. Implement the business-integrated quality systems through process control (LO: 2.7 & 2.8). 2. Use quality improvement tools and practices for continuous improvement. (LO: 3.5 & 3.8). 3. Develop strategies for...
Portfolio Activity This course covers various aspects of managerial accounting that are meant to give you...
Portfolio Activity This course covers various aspects of managerial accounting that are meant to give you the foundation needed to understand, analyze and evaluate a company’s performance as a company manager as well as an external user of financial information. Given your personal and professional goals, which of these tools will be of greatest benefit to you (describe at least 3)? Why? Be specific. Please give accurate answers Please do not plagiarise Please do not post any answer already here
This assignment is aligned to these course outcomes: Explain economic principles and their applications in the...
This assignment is aligned to these course outcomes: Explain economic principles and their applications in the real world. Summarize the different types of market structures and the role of government in economics. In the workplace, we are often asked to create “briefs.” A brief provides a snapshot, or short, written summary, of a situation or event that has occurred. It is generally just a few pages long and may include additional visuals like a graph, chart, or table. In this...
Course: Security Architecture & Design Assignment - Executive Program Practical Connection Assignment Provide a reflection of...
Course: Security Architecture & Design Assignment - Executive Program Practical Connection Assignment Provide a reflection of at least 500 words (or 2 pages double spaced) of how the knowledge, skills, or theories of this course have been applied, or could be applied, in a practical manner to your current work environment. If you are not currently working, share times when you have or could observe these theories and knowledge could be applied to an employment opportunity in your field of...
please I want new answer The Assignment`s learning Outcomes: In the second assignment for the Quality...
please I want new answer The Assignment`s learning Outcomes: In the second assignment for the Quality Management course, the students are required to read the “ Nestlé Waters Unifying real-time visibility across 26 factories” case study , and answer the related questions, upon successful completion of the assignment the student should be able to: 1. Implement the business-integrated quality systems through process control (LO: 2.7 & 2.8). 2. Use quality improvement tools and practices for continuous improvement. (LO: 3.5 &...
Product and Place (Distribution) The following Course Outcomes are assessed in this Assignment: AB219-4: Apply product...
Product and Place (Distribution) The following Course Outcomes are assessed in this Assignment: AB219-4: Apply product and place Marketing Mix elements to a product or service. GEL-6.02: Incorporate outside research into an original work appropriately. Unit 8, Part 2: Continued from Unit 7 Assignment You can review Unit 7, Part 1 summarized. Assume Proservice’s new product you selected in Unit 7 initially used a direct channel of distribution (i.e., the producer sells directly to the consumer via their website) to...
Quantitative Methods II This assignment relates to the following Course Learning Requirements: [CLR 1] Calculate the...
Quantitative Methods II This assignment relates to the following Course Learning Requirements: [CLR 1] Calculate the chance that some specific event will occur at some future time • knowledge of the normal probability distribution [CLR 2] Perform Sampling Distribution and Estimation [CLR 3] Conduct Hypothesis Testing [CLR 4] Understand and calculate Regression and Correlation Objective of this Assignment:    To conduct a regression and correlation analysis Instructions: The term paper involves conducting a regression and correlation analysis on any topic of...
Course : Knowledge Management Assignment outcomes: 1. Identify the problems and make strategies to cope with...
Course : Knowledge Management Assignment outcomes: 1. Identify the problems and make strategies to cope with the critical situation. 2. How organization use IT tools to implement the Knowledge Management system. 3. Understand the initial step in implicit knowledge and How to convert technical implicit knowledge into explicit. Case Study This assignment is a case study about knowledge management. Read it carefully and answer the questions given at the end. Note: Ø Each question carries 2 marks Ø Be very...
Write a short summary that supports your achievement of the course clinical learning outcomes for evidence-based practice.
Write a short summary that supports your achievement of the course clinical learning outcomes for evidence-based practice. Refer to the clinical learning outcomes listed on the course clinical evaluation tool, and provide specific examples of how you met the learning outcome.
Course Learning Outcomes-Covered • Demonstrate a solid understanding of decision making process for complex issues pertaining...
Course Learning Outcomes-Covered • Demonstrate a solid understanding of decision making process for complex issues pertaining to business environment both internally and externally. (1.2) • Explain critical thinking and cognitive psychology as it pertains to analyze and synthesize information for problem solving and decision making. (2.7) • Identify and analyze different perspectives on understanding problems for different situations. (3.1) Assignment Instructions: • Log in to Saudi Digital Library (SDL) via University’s website • On first page of SDL, choose “English...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT