Explore BrainMass
Share

Three example C++ programs

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Please assist with questions 1, 2, and 3... do not assist with 4. Please see the attached file.

© BrainMass Inc. brainmass.com October 24, 2018, 11:59 pm ad1c9bdddf
https://brainmass.com/computer-science/sorting/three-example-programs-212554

Attachments

Solution Preview

This solution addresses the first three questions in the posting. Each question has an associated cpp file.

The first question deals with sorting an array of names. The sort algorithm used is the bubble sort. The bubble sort is a simple but inefficient sorting algorithm. Due to its simplicity it is easy to implement. However, for longer data sets its inefficiency makes it unsuitable for use.

The basic bubble sort algorithm is to go through the list, from front to back, and compare adjacent elements. If the elements are out of order, swap them. After making one pass through the list then the largest element is guaranteed to be at the end of the list. It
"bubbled" to the end. Since each full pass of the list guarantees the one more element will be in the correct location, we need to do "n" passes. The ...

Solution Summary

This solution provides three complete C++ programs. The first program uses a bubble sort to sort a list of strings. The second calculates the difference between two dates. The third shows how to calculate the roots of a polynomial.

$2.19
See Also This Related BrainMass Solution

C++

l. Create a program to determine the smallest number out of 15 numbers entered (numbers entered one at a time from the keyboard). This should be done in prototype:
double smaller (double x, double y);
Make sure you use a for loop expression inside your function. Be sure to include your program prompts for input and a display of the smallest number when you have found it.

2. You are a mortgage broker who is determining whether you should provide a mortgage to
perspective home purchasers. If you are willing to provide a mortgage, you need to
decide how much you should charge the borrower. You design a point system that
assigns perspective borrowers a score of 1,2,3,4, or 5 based on some mysterious
formula. Based on these scores, you come up with the following decisions:
Score Decision
5 Provide mortgage at 5% interest rate
4 Provide mortgage at 6% interest rate
3 Provide mortgage at 7% interest rate
2 Do not provide mortgage
1 Do not provide mortgage

Create a program that takes the scores as input and provides as output the management
decision. In the program, include 2 void functions titled getScore and printdecision,
each with an int argument.

? The function getScore should have a Reference parameter that gets the score in
getScore and then passes the value back to be printed in main (), and
? print Decision should have a Value parameter.

The function getScore will prompt the user for the integer score from 1 to 5, get the input
from the user, and display the input received on the screen. The function printDecision
will determine the mortgage decision and print the decision. (Be careful and note that
this problem requires you to input the score into getScore and not directly into the main
function.)

3. Define a class called Date that has 3private members that represent the month, day, and year respectively. They will be represented as integers. Include a constructor and a public void function called print that prints out the date. (For example, if the month is 2, the day is 25, and the year is 1946, print provides as output 2/25/1946.) Include the class in a program that prints out the date 2/25/1946.

L. Create a program to determine the smallest number out of 15 numbers entered (numbers entered one at a time from the keyboard). This should be done in prototype:
double smaller (double x, double y);
Make sure you use a for loop expression inside your function. Be sure to include your program prompts for input and a display of the smallest number when you have found it.

2. You are a mortgage broker who is determining whether you should provide a mortgage to
perspective home purchasers. If you are willing to provide a mortgage, you need to
decide how much you should charge the borrower. You design a point system that
assigns perspective borrowers a score of 1,2,3,4, or 5 based on some mysterious
formula. Based on these scores, you come up with the following decisions:
Score Decision
5 Provide mortgage at 5% interest rate
4 Provide mortgage at 6% interest rate
3 Provide mortgage at 7% interest rate
2 Do not provide mortgage
1 Do not provide mortgage

Create a program that takes the scores as input and provides as output the management
decision. In the program, include 2 void functions titled getScore and printdecision,
each with an int argument.

? The function getScore should have a Reference parameter that gets the score in
getScore and then passes the value back to be printed in main (), and
? print Decision should have a Value parameter.

The function getScore will prompt the user for the integer score from 1 to 5, get the input
from the user, and display the input received on the screen. The function printDecision
will determine the mortgage decision and print the decision. (Be careful and note that
this problem requires you to input the score into getScore and not directly into the main
function.)

3. Define a class called Date that has 3private members that represent the month, day, and year respectively. They will be represented as integers. Include a constructor and a public void function called print that prints out the date. (For example, if the month is 2, the day is 25, and the year is 1946, print provides as output 2/25/1946.) Include the class in a program that prints out the date 2/25/1946.

View Full Posting Details