Professional Documents
Culture Documents
CSC425 Take Home Test 2
CSC425 Take Home Test 2
CSC425 Take Home Test 2
PART A
1. D 9. B
2. D 10. C
3. A 11. B
4. A 12. B
5. D 13. A
6. B 14. B
7. A 15. D
8. B
PART B
QUESTION 1 (a)
Syntax Errors:
1. char step;
2. char vowel[]=a,e,i,o,u;
3. while (step;step < 4;step++);
4. cout>>vowel[step];
QUESTION 1 (b)
#include <iostream>
using namespace std;
int main()
{
int n;
int x[] = {4,2,8,9,3,12,5,0,14,1};
{
for (int n=14; n>0; n--)
{
cout<<n<<", ";
}
}
cout<<"The largest number is: "<<n<<endl;
}
QUESTION 2
#include <iostream>
using namespace std;
void doInvestment();
int main()
{
void doInvestment();//doInvestment Function
/*
currBal - current balance of user
annualInvestment - amount the user will invest each year
returnRate - percentage of the annual dividend
endGoal - amount user wants to end up with.
*/
#include <iostream>
using namespace std;
int main()
{
int input, remainder, even = 0, odd = 0;
int evenArray[even];
int oddArray[odd];
int total_evenArray,average_evenArray, sum;
cout << "This program accepts integers until you enter 0.\nEnter any value: ";
cin >> input;
while (input != 0)
{
remainder = input % 2;
if (remainder == 0)
{
evenArray[even] = input;
even++;
}
else
{
oddArray[odd] = input;
odd++;
}
cout << "Enter another integer: ";
cin >> input;
}
cout << "\nThe number of evens is " << even << ".\n";
cout << "The evenArray numbers are: ";
for(int i = 0; i < even; i++)
{
cout << evenArray[i] << " "<<endl;
}
total_evenArray= ;
{
cout<<"The total of numbers in evenArray is= "<<total_evenArray<<endl;
}
average_evenArray=total_evenArray/even;
{
cout<<"The average of numbers in evenArray is: "<<average_evenArray<<endl;
}
}