Exercise 03

Page 1 of 2

1. Write a program with a function that takes two int parameters, adds them together, and then returns the sum. The program should ask the user for two numbers, then call the function with the numbers as arguments, and tell the user the sum. 2. Basically the same as Prob 1, but this time, the function that adds the numbers should be void, and takes a third, pass by reference parameter; then puts the sum in that. 3. Using permutation function, write a program that calculates the following expression: P(n,k) = (n!) / (n-k)! 4. Using permutation function, write a program that calculates the following expression which is more effective than the previous one to find the permutation of P: P(n,k) = n . (n-1) . (n-2) . … … … (n-k+2) (n-k+1) 5. Using combination function, write a program that calculates the following expression: C(n,k) = (n!) / {k! (n-k)!} 6. Using functions, write a program that calculates the following expression: C(n,k) = P (n,k) / k! 7. Following Triangle is known as Pascal’s Triangle. 1

1 1 1 1

1 7

6

1 5 21

4 15

1 3 10 35

2 6 20

1 3 10 35

1 4 15

1 5 21

1 6

1 7

1 1

Each number in this Triangle is one of the combinations C(n,k); where n is row number and k is column number. For Example, C(6,2) = 15. Write a program that uses a comb() function to print the triangle down to row number 12. Hints: Use setw() function to fix the column width. Run the following program to see the function of setw(). #include // defines setw() #include using namespace std; int main() { for (int x=1; x <= 6; x++) { for (int y=1; y <= 6; y++) if (y > x) break; else cout << setw(4) << x*y; cout << endl; }}

8. Write and test the a function SQUARE(int n) that determines whether the given integer is a square number. The output will be as follows: 0 is square. 1 is square. 2 is not square. 3 is not square. 4 is square. 5 is not square. 6 is not square. 7 is not square. 8 is not square. 9 is square. 10 is not square. 11 is not square. 12 is not square. 13 is not square. 14 is not square. 15 is not square. 16 is square. Press any key to continue_

Exercise 03

Page 2 of 2

9. Write and test the following function that returns the area a and the circumference c of a circle with given radius r: void Circle (float& a, float& c, float r)

Output screen will be like this : Enter the radius: 2 The area of a circle of radius 2 is 12.5664 and its circumference is 12.5664 Press any key to continue_ 10. Write and test the following function that returns the area a and the perimeter p of a triangle with given sides of s1, s2, s3: void Circle (float& a, float& p, float s1, float s2, float s3)

11. Explain the following source code line by line. Also show the output screen. #include using namespace std; void f(); void g(); int x = 11; int main() { int x = 22; { int x = 33; cout << "In block inside main(): x = " << x << endl; } cout << "In main(): x = " << x << endl; cout << "In main(): ::x = " << ::x << endl; f(); g(); } void f() { int x = 44; cout << "In f(): x = " << x << endl; } void g() { cout << "In g(): x = " << x << endl; }

1. Write a program with a function that takes two int ...

Write and test the a function SQUARE(int n) that determines whether the given integer is a square number. The output will be as follows: 0 is square. 1 is square. 2 is not square. ... void Circle (float& a, float& p, float s1, float s2, float s3). 11. Explain the following source code line by line. Also show the output screen. #include ...

82KB Sizes 1 Downloads 109 Views

Recommend Documents

1. Write a program that will sort some given value in ...
Write a program that will sort some given value in ascending and descending order. 2. Write a program that will calculate the average of the data that has been ...

POSH: A TLS Compiler that Exploits Program Structure
piler infrastructure. We perform our transformations in the tree SSA high-level intermediate representation [11]. 3.3 Profiler. The profiler provides a list of tasks ...

Postsecondary Enrollment Options (PSEO) is a program that allows ...
and 12th-grade students to earn both high school and college credit while still in ... courses are offered online. ... take one career/technical PSEO course.

Supplement to “A Critical Value Function Approach, with an ...
Jun 6, 2016 - transformations on the data g ◦ (y, x)=(y + Dg, x) , where g ... Fig S2: Critical Value Function (intercept and time trend). (a) ρ = 0.95. (b) ρ = −0.95.

Supplement to “A Critical Value Function Approach, with an ...
Jun 6, 2016 - this graph with Figure 1, it is evident that both bootstrap methods and subsampling have null rejection probabilities farther away from the 10% ...

How Do You Write a Song That Will Knock Over a Cow?
What is the total cost? 3. Betty takes out a ... How much must she pay per month? 4. ... If she wants to pay off the loan in 4 years, how much can Sarah borrow? 9.

A Critical Value Function Approach, with an Application ...
Jun 6, 2016 - Application to Persistent Time-Series. Marcelo J. ...... model. If the model has one lag, Hansen [9] suggests a “grid” bootstrap which delivers. 15 ...