# A Company Invests \$10,000 Today To Be Repaid In 5 Years In [Solved]

Question 1

Question 2

Creat a file named employee.txt containing the following data:

1. Amaya A 10031 9.82 12/18/13
2. Cecilia W 10067 9.14 6/9/13
3. Karida B 10083 8.79 5/18/12
4. Janney P 10095 10.57 9/28/12

Write a c++ program to read the employee.txt file and produce a duplicate copy of the file named employee.bak.

Accept the names of the original and duplicate files as user input.

(You can provide a default duplicate file name for users)

Question 3

Given the following, use C++. A concrete manufacturing company is developing five new formulations to use for highways. To ensure that the formulations produce similar results when they are prepared by plants in different locations, the company has asked each of the seven plants to prepare each formulation and measure the compressive strength after 180 days of curing. You have been asked to develop a program to help analyze the data. Your program should have a main function and 3 other functions as described below.

One function should confirm that the entered value for compressive strength is between 15 and 75 MPa inclusive. This function should accept the compressive strength to be checked and the plant number that measured this strength and prompt the user to re-enter the compressive strength for that plant until a valid value is entered. This function should return a valid value to the function call.

One function should accept the 7 compressive strengths from a plant and send back to function the highest and lowest of the 7 compressive strengths to the function call.

One function should accept the 7 compressive strengths of a specific formulation and calculate the average of the strengths for that formulation without the highest and lowest strength. This function should call the function to determine the lowest and highest compressive strength for a plant, then calculate the average. The average should be returned to the function call.

The main function should prompt the user to enter the compressive strength for a formulation from each plant one at a time and call the function to ensure the entered value was valid. Next main should call the function to calculate the average of the values from the plants. This process should be repeated for each of the 5 formulations. The main function should output the average for each formulation to two decimal places.

Use basic code to complete this project (e.g. do not use arrays. Make sure that you have included your introductory comments containing the purpose of the program i.e. what problem or task is being solved plus the input needed from user to complete the problem/task, output expected from the program, and the processing needed to get the output from the input. The description of the purpose should be detailed enough that a person reading your code would not need any additional information to understand the problem. The processing comments should not include any C++ commands.

Answer to question 1

Answer
real interest rate =(interest rate -inflation )/(1+inflation)
=(0.12-0.03)/(1.03)
=0.0873786408
=8.73786%
FV=PV*(1+i)^n
PV=present value =10000
i=real interest rate
n=5 yras

FV=10000*(1+0.0873786408)^5
=15202.1142
the profit =FV-PV=15202.1142-10000
=5202.1142
The profit earned is \$5200 (approximatly)

option b

Answer to question 2

1. #include <iostream>
2. #include <fstream>
3. #include <string>
4. using namespace std;
5. int readEmployeeFileAndProduceDuplicateCopy(string inputFileName, string outputFileName)
6. {
7. ifstream inFile;
8. ofstream fout;
9. string str;
10.
11.            inFile.open(inputFileName);
12.                 if (!inFile) {
13.                       // Unable to open file
14.                       return (-1); // terminate with error
15.                 }
16.
17. fout.open(outputFileName);
18. do
19.                 {
20.                          getline(inFile, str);
21.          // Write to file
22.                         fout << str << endl;
23.         } while (!(inFile.eof()));
24.
25. // Close the input and output File
26.                 inFile.close();
27.                 fout.close();
28. return 0;
29. } // end of function
30. int main()
31. {
32.   int res;
33.   string inputFileName;
34.   string outputFileName = “employee.bak”;
35.
36.
37.   cout << ” Please enter the name of the original file:” ;
38.   cin >> inputFileName;
39.
40.   cout << ” Please enter the name of the duplicate file:” ;
41.   cin >> outputFileName;
42.
43.   res = readEmployeeFileAndProduceDuplicateCopy(inputFileName,outputFileName);
44.   if (res == 0) // file exist
45.   {
46.       cout << ” Duplicate file with name ” << outputFileName << ” created. ” << endl;
47.   } // end of if()
48.   else
49.       cout << ” Unable to open the Original file with name ” << inputFileName << endl;
50.
51.   return 0;
52. }

Answer to question 3

The application can be developed using basic programming constructs. The following 3 functions are implemented.

1. checkValidityOfInputData() : This function checks if the input value is within the allowed range of 15 to 75 inclusive.

Till the time, user provides a valid value, it prompt the user to provide the input again and again within a While() loop. Once a valid value is provided , it is returned to the calling function.

2. getHighestNLowestComStrenght(): This function checks for the highest and the lowest compressive Strength value from the given set of 7 data values. This function is passed the 7 data values along with 2 reference variables hi and lo. Due to passed by reference technique, their assigned value in this function would be reflected in the calling function.

To get the highest value, we check if each of the data value is greater than or equal to the remaining 6 values, if yes, hi is assigned that data value.

To get the lowest value, we check if each of the data value is less than or equal to the remaining 6 values, if yes, lo is assigned that data value.

3. findAverage(): This function finds the average of the seven data values after subtracting the highest and the lowest value.

We first call the function getHighestNLowestComStrenght() to get the highest and the the lowest value.

We then add all the 7 data values and subtract highest and lowest value.

The sum is then divided by 5 to get the average. The average is returned to the calling function.

In the main function,for each factory, we get the 7 compressive strengths value of each formulation, validate the input thru checkValidityOfInputData(), and then call findAverage() to calculate the average. The average is displayed to the user.

1. #include <iostream>
2. using namespace std;
3. #define MAX_NO_OF_PLANT 7
4. // functions declaration
5. int checkValidityOfInputData(int pNumber, int compressivStrength );
6. void getHighestNLowestComStrenght(int d1, int d2,int d3, int d4,int d5,int d6,int d7,int &highest,int &low );
7. float findAverage(int d1, int d2,int d3, int d4,int d5,int d6,int d7);
8. // Main function for the program
9. int main( )
10. {
11. float average;
12. int formulationCount = 1;
13. int numberOfPlants;
14. int CS1,CS2,CS3,CS4,CS5,CS6,CS7;
15. int highestCS,lowestCS;
16.   for (numberOfPlants = 1;numberOfPlants<= MAX_NO_OF_PLANT; numberOfPlants++)
17.   { /* for each of the plant ..*/
18.    formulationCount = 1;
19.     while (formulationCount <= 5)
20.     { /* get the 7 compressive strength values for each of the 5 formulation */
21.
22.              cout << “Plant Number = “<< numberOfPlants << endl;
23. cout << “Formulation Count = ” << formulationCount << endl;
24. cout << “Enter first value of compressive strength : “;
25.      cin >> CS1;
26.              /* check if the entered value is valid that is within 15 and 75 MPa */
27.             CS1 = checkValidityOfInputData(numberOfPlants,CS1);
28.
29.             cout << “Enter second value of compressive strength : “;
30.             cin >> CS2;
31.             /* check if the entered value is valid that is within 15 and 75 MPa */
32.             CS2 = checkValidityOfInputData(numberOfPlants,CS2);
33.
34.             cout << “Enter third value of compressive strength : “;
35.             cin >> CS3;
36.             /* check if the entered value is valid that is within 15 and 75 MPa */
37.             CS3 = checkValidityOfInputData(numberOfPlants,CS3);
38.
39.             cout << “Enter fourth value of compressive strength : “;
40.             cin >> CS4;
41.               /* check if the entered value is valid that is within 15 and 75 MPa */
42.             CS4 = checkValidityOfInputData(numberOfPlants,CS4);
43.
44.        cout << “Enter fifth value of compressive strength : “;
45.             cin >> CS5;
46.              /* check if the entered value is valid that is within 15 and 75 MPa */
47.             CS5 = checkValidityOfInputData(numberOfPlants,CS5);
48.
49.        cout << “Enter sixth value of compressive strength : “;
50.             cin >> CS6;
51.             /* check if the entered value is valid that is within 15 and 75 MPa */
52.             CS6 = checkValidityOfInputData(numberOfPlants,CS6);
53.
54.            cout << “Enter seventh value of compressive strength : “;
55.            cin >> CS7;
56.            /* check if the entered value is valid that is within 15 and 75 MPa */
57.            CS7 = checkValidityOfInputData(numberOfPlants,CS7);
58.
59.            /* calculate the average of the values provided */
60.           average = findAverage(CS1,CS2,CS3,CS4,CS5,CS6,CS7);
61.           cout << endl ;
62.           cout << “Average of the values from plant “<< numberOfPlants << ” , ” << ” Formulation ” << formulationCount << ” is ” << average << endl;
63.           cout << endl ;
64.
65.           formulationCount++;
66.
67. } /* end of while loop */
68.   } /* end of while loop */
69. return 0;
70. }
71. // functions definitions
72. /* This function checks if the input value is within the allowed range of 15 to 75 inclusive */
73. int checkValidityOfInputData(int pNumber, int compressivStrength )
74. {
75. while (!(( compressivStrength >= 15 ) && (compressivStrength <= 75)))
76. { /* till the time, user provides the valid value, prompt the user to provide the input again */
77. cout << “Invalid Value entered. Please provide value again.”<<endl;
78. cout << “Plant Number = “<< pNumber << endl;
79. cout << “Enter value of compressive strength : “;
80.              cin >> compressivStrength;
81. }
82. /* return the valid value */
83. return compressivStrength;
84. }
85. /* this function checks for the highest and the lowest compressive Strength value from the given data */
86. /* int hi and int lo are passed by reference and hence their assigned value in this function would be
87.    reflected in the calling function */
88.
89. void getHighestNLowestComStrenght(int d1, int d2,int d3, int d4,int d5,int d6,int d7,int &hi,int &lo)
90. {
91. /* d1 is the highest value if d1 is greater tahn or equal to all the other values */
92. if ( (d1 >= d2)&&(d1 >= d3)&&(d1>=d4)&&(d1>=d5)&&(d1>=d6)&&(d1>=d7))
93.     hi = d1;
94. /* d2 is the highest value if d2 is greater tahn or equal to all the other values */
95. if ( (d2 >= d1)&&(d2 >= d3)&&(d2>=d4)&&(d2>=d5)&&(d2>=d6)&&(d2>=d7))
96.     hi = d2;
97. /* d3 is the highest value if d3 is greater tahn or equal to all the other values */
98. if ( (d3 >= d1)&&(d3 >= d2)&&(d3>=d4)&&(d3>=d5)&&(d3>=d6)&&(d3>=d7))
99.     hi = d3;
100. /* d4 is the highest value if d4 is greater tahn or equal to all the other values */
101. if ( (d4 >= d2)&&(d4 >= d3)&&(d4>=d1)&&(d4>=d5)&&(d4>=d6)&&(d4>=d7))
102.     hi = d4;
103. /* d5 is the highest value if d5 is greater tahn or equal to all the other values */
104. if ( (d5 >= d2)&&(d5 >= d3)&&(d5>=d4)&&(d5>=d1)&&(d5>=d6)&&(d5>=d7))
105.     hi = d5;
106. /* d6 is the highest value if d6 is greater tahn or equal to all the other values */
107. if ( (d6 >= d2)&&(d6 >= d3)&&(d6>=d4)&&(d6>=d5)&&(d6>=d1)&&(d6>=d7))
108.     hi = d6;
109. /* d7 is the highest value if d7 is greater tahn or equal to all the other values */
110. if ( (d7 >= d2)&&(d7 >= d3)&&(d7>=d4)&&(d7>=d5)&&(d7>=d6)&&(d7>=d1))
111.     hi = d7;
112.
113. /* d1 is the lowest value if d1 is less tahn or equal to all the other values */
114. if ( (d1 <= d2)&&(d1 <= d3)&&(d1<=d4)&&(d1<=d5)&&(d1<=d6)&&(d1<=d7))
115.     lo = d1;
116. /* d2 is the lowest value if d2 is less tahn or equal to all the other values */
117. if ( (d2 <= d1)&&(d2 <= d3)&&(d2<=d4)&&(d2<=d5)&&(d2<=d6)&&(d2<=d7))
118.     lo = d2;
119. /* d3 is the lowest value if d3 is less tahn or equal to all the other values */
120. if ( (d3 <= d1)&&(d3 <= d2)&&(d3<=d4)&&(d3<=d5)&&(d3<=d6)&&(d3<=d7))
121.     lo = d3;
122. /* d4 is the lowest value if d4 is less tahn or equal to all the other values */
123. if ( (d4 <= d2)&&(d4 <= d3)&&(d4<=d1)&&(d4<=d5)&&(d4<=d6)&&(d4<=d7))
124.     lo = d4;
125. /* d5 is the lowest value if d5 is less tahn or equal to all the other values */
126. if ( (d5 <= d2)&&(d5 <= d3)&&(d5<=d4)&&(d5<=d1)&&(d5<=d6)&&(d5<=d7))
127.     lo = d5;
128. /* d6 is the lowest value if d6 is less tahn or equal to all the other values */
129. if ( (d6 <= d1) && (d6 <= d2)&&(d6 <= d3)&&(d6<=d4)&&(d6<=d5)&&(d6<=d7))
130.     lo = d6;
131. /* d7 is the lowest value if d7 is less tahn or equal to all the other values */
132. if ( (d7 <= d2)&&(d7 <= d3)&&(d7<=d4)&&(d7<=d5)&&(d7<=d6)&&(d7<=d1))
133.     lo = d7;
134. }
135. /* this function finds the average of the seven data values after subtracting the highest and the lowest value */
136. float findAverage(int d1, int d2,int d3, int d4,int d5,int d6,int d7)
137. {
138.    int high, low;
139.    int sum = 0;
140.    float average;
141.
142.    /* get the highest and the the lowest value */
143.    getHighestNLowestComStrenght(d1,d2,d3,d4,d5,d6,d7,high,low);
144.    cout << “largest value = ” << high << ” lowest value = ” << low << endl;
145.
146.    /* add all the 7 data values and subtract high and low */
147.    sum = d1 + d2 + d3 + d4 + d5 + d6 + d7 – high – low ;
148.    cout << “SUM = “<< sum << endl;
149.
150.    /* find average */
151.    average = (float)sum/5; /* 5 because only 5 data values are used */
152.
153.    return average;
154.
155. }

Categories Q&A