Name: ____________________________________________________ Alpha:
_____________ Section: ________
Describe help received: _________________________________________________________________
See the bottom for how to submit your work.
Due: Before 0800 on next class day
|
|
|
circle one:
|
circle one:
|
circle one:
|
5 1.1 -1.3 4 -7.4 -3.6... the program should output the following:
Negatives in reverse: -3.6 -7.4 -1.3However, the program doesn't work as it is intended to. Fix the bugs by annotating in the code directly. (Hint: There are 6 bugs).
Note: A similar question will appear in the exam. Try to solve the problem by hand (and then double-check your answer by compiling and running your solution).
// fix the bugs!!
1 #include <iostream>
2 using namespace std;
3
4 void print_negatives(double* A, int N);
5
6 int main()
7 {
8 int N=0;
9 double* A = new double[N];
10 cin >> N;
11
12 for(int i=0; i<N; i++)
13 cin >> A[N];
14
15 cout << "Negatives in reverse:" << endl;
16
17 void print_negatives(double* A, int N);
18
19 delete [] A;
20
21 return 0;
22 }
23
24 void print_negatives(int* A, int N)
25 {
26 for(int i = N; i >= 0; i--)
27 cout << A[i] << endl;
28 }