0% found this document useful (0 votes)
108 views3 pages

CSC425 Take Home Test 2

This document contains a take home test with multiple parts and questions. Part A contains a multiple choice question section with 15 questions. Part B contains 3 programming questions that involve syntax errors, calculating investment returns over years, and separating even and odd numbers entered by the user into arrays. The questions test programming skills and require analyzing, debugging, and writing code to solve the posed problems.

Uploaded by

hnrakinah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views3 pages

CSC425 Take Home Test 2

This document contains a take home test with multiple parts and questions. Part A contains a multiple choice question section with 15 questions. Part B contains 3 programming questions that involve syntax errors, calculating investment returns over years, and separating even and odd numbers entered by the user into arrays. The questions test programming skills and require analyzing, debugging, and writing code to solve the posed problems.

Uploaded by

hnrakinah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 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;
}
}

You might also like