我的。。。C++ 怎么办

Stifler

资深人士
VIP
注册
2003-12-29
消息
22,414
荣誉分数
92
声望点数
208
压。。。


totally 死了
 
Part II
Write a program that produces a table showing how different interest rates affect the number of
years that will pass before the money runs out. Your program should read in the initial savings
(i.e. “x”) and the annual spending (i.e. “y”). If the values entered are unreasonable (either value
is zero or negative, or “y” is greater than “x”) or invalid (i.e. total garbage) your program should
output an error message and have the user try again, and repeat this until reasonable values are
obtained. The table should cover interest rates from 2% to 10% (in steps of 0.5%). Each line
should show the interest rate, the number of years until the money runs out, and the amount
remaining in the account when the money runs out. If the money will never run out, the normal
line should be replaced with a message to this effect and any further table lines should be
skipped (because they would, if output, all say the same thing). Do not waste time counting
columns and making your table appear exactly like that in the sample run below. You should,
ECOR 1606 Page 3 of 7 December 2003
ECOR 1606 Page 2 of 7 December 2003
Question #1: (25 marks)
Imagine that somebody is about to retire. They have “x” dollars in savings, and plan to spend
“y” dollars every year. At the start of every year (January 1st) they will withdraw “y” dollars
from their savings account. At the end of every year (December 31st) their bank will pay interest
(at “z” percent) on the money remaining in the account. The following example should make
things clear.
Suppose “x” = $100,000, “y” = $20,000, and “z” = 5%
Year 1: $20,000 withdrawn, leaving $80,000
interest = 0.05 * $80,000 = $4,000
money at end of year = $84,000
Year 2: $20,000 withdrawn, leaving $64,000
interest = 0.05 * $64,000 = $3,200
money at end of year = $67,200
… and so on.
In general, the money will eventually run out. Come some January 1st, the man will find that he
does not have enough money left to get him through the year. Although there may still be some
money left in the account, that amount is less than “y”. It is possible, however, that the money
will never run out. This will happen if the interest earned every year equals or exceeds the
amount of money spent.
Part I
Write a function that, given “x”, “y”, and “z”, returns the number of full years that will pass
before the money runs out. If the money will never run out, your function should return “-1”. If
the money will run out, your function should also “return” the amount of money that will be left
in the saving account when this happens.
You may assume that the values supplied to your function will be reasonable (i.e. that “x”, “y”,
and “z” will all be greater than zero). Do not worry about the fact that monetary amounts may
involve fractional cents.

however, fully demonstrate your knowledge of outputting formatting. Note that dollar amounts
should be output with two digits after the decimal point.
Enter initial savings and annual spending: 500000 -6
*** Unreasonable or invalid values rejected. ***
Enter initial savings and annual spending: total junk
*** Unreasonable or invalid values rejected. ***
Enter the initial savings and annual spending: 500000 30000
Interest Rate Years Money Left
-----------------------------------
2.0 19 29484.49
2.5 21 3905.25
3.0 22 14465.19
3.5 24 3168.54
4.0 26 3708.46
4.5 28 22159.00
5.0 32 10557.61
5.5 37 28405.31
6.0 49 8674.88
6.5 The money will never run out.
 
Question #2: (7 marks)
Write a function that, given a string, replaces all occurrences of a specified character with
another specified character. Your function must be compatible with the following sample call:
char sample[60] = "This is the original string. I like it.";

editString(sample, 'i', 'x'); // change all occurrences of 'i' to 'x'

cout << sample << endl;

// output will be "Thxs xs the orxgxnal strxng. x lxke xt."
If the character to be replaced is a letter, both upper and lower case instances of the letter should
be replaced.
 
This question assumes the structure declarations given below:
struct midtermResult {
bool wrote; // true if student wrote the midterm, false otherwise
double mark; // midterm mark, meaningless if "write" is false
};

struct studentData {
char name[80]; // student name
int number; // student number
midtermResult midterms[3]; // results for the three midterms
};
Write a function that, given an array of “studentData” structures (and the length of this array),
returns the number of students who have failed to pass (get 5 or more on) at least one of the
midterms.
 
废了,就不上学了。。我。。。或者转行
 
editString(char sample[], char a, char b) {
for (int i = 0; i < sample.length(); i++) {
if (sample == b)
sample = a;
}
}

..............
 
int failNumber(studentData a [], int length) {
int failed;
bool failedAtLeastOne;
for (int i = 0; i < length; i++) {
for (int j = 0; j < 3 && !failedAtLeastOne; j ++) {
if (!a.midterms[j].wrote || a.midterms[j].mark < 5)
failed ++;
failedAtLeastOne = true;
}
failedAtLeastOne = false;
}
return failed;
}




something like that
 
最初由 Assticker 发布
太强了。。楼上的



。。。。。不是我太强,是你们这个考试太那个了吧。。
 
这个不是考试的,是以前的
 
后退
顶部