Вы находитесь на странице: 1из 3

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

int year=1990;//current year


double currBal, annualInvestment, returnRate, endGoal;

/*
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.
*/

cout<<"Amanah Saham Berhad"<<endl<<endl;


cout<<"Enter the starting amount of your investment:RM ";
cin>>annualInvestment;

cout<<"Enter the yearly percentage rate of return(%): ";


cin>>returnRate;

cout<<"Enter your investment goal:RM ";


cin>>endGoal;

currBal = annualInvestment;//start off with the annual investment.

while (currBal <= endGoal)//main loop


{
cout<<"Year: "<<year<<endl;//displaying the current year
cout<<"Year's Beginning Balance: "<<currBal<<endl;
currBal = (currBal + annualInvestment) + (annualInvestment*returnRate/100);
cout<<"Year's Ending Balance: "<<currBal<<endl<<endl;
year++;//go to the next year
}
cout<<"You will get "<<endGoal<<" that you have invested in "<<year-1990<<"
years."<<endl;
}
QUESTION 3

#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;
}
}

Вам также может понравиться