Programming Assignment Assignment

Language: C++.

Question #1
Simple introduction question (5 points) Using a for loop, write a function to compute the k-th power of a number : double power(double x, int k)

Question #2
Using two-dimentional arrays, write a function (and a corresponding program to test it) which multiplies an mxn matrix of integers by an nxr matrix of integers. Use global constant declarations before the main program to give test values for m, n and r. Example input/output might be:
INPUT FIRST (2x2) MATRIX: Type in 2 values for row 1 Type in 2 values for row 2 INPUT SECOND (2x2) MATRIX: Type in 2 values for row 1 Type in 2 values for row 2 3 5 TIMES 1 2 EQUALS 11 19 11 19 1 2 4 7 separated by spaces: 3 4 separated by spaces: 5 7 separated by spaces: 1 1 separated by spaces: 2 2

28 is a perfect number because it is the sum of 1. and 14. Write a predicate function IsPerfect that takes an integer n and returns true if n is perfect.Question #3 Greek mathematicians took a special interest in numbers that are equal to the sum of their proper divisors (a proper divisor of N is any divisor less than N itself). 4. 6 is a perfect number because it is the sum of 1. and 3. which are the integers less than 6 that divide evenly into 6. For example. and false otherwise. your program should display it on the screen. Your program should find two other perfect numbers in the range as well. Similarly. When a perfect number is found. 2. . 7. The first two lines of output should be 6 and 28. They called such numbers perfect numbers. 2. Test your implementation by writing a main program that uses the IsPerfect function to check for perfect numbers in the range 1 to 9999 by testing each number in turn.

Write the definitions of the member functions of the class bookType. and year of publication. Set to 5 components. up to four authors. and number of copies in stock. 1. Write a program that uses the class bookType and test the various operations on the objects of class bookType. book price. For example.Question #2 Class and Data Abstraction Some of the characteristics of a book are the title. Each object of the class bookType can hold the following information about a book: title. Add the appropriate constructors and a destructor ( if one is needed). the usual operations that can be performed on the title are to show the title. author(s). 2. Declare an array of 100 components of the type bookType. ISBN. add another data member. and return the number of copies in stock. price. To keep track of the number of authors. Design a class bookType that defines the book as an ADT. update the number of copies in stock. 3. Similarly. and author. Include the member functions to perform the various operations on objects of the type bookType. ISBN. and check whether a title is the same as the actual title of the book. Display the output. Add similar operations for the publisher. ISBN. set the number of copies in stock. . the typical operations that can be performed on the number of copies in stock are to show the number of copies in stock. publisher. price. publisher.