Assignment-4 Solution

$30.00 $24.00

Objectives: This assignment gives you some experience with writing C++ programs that use funda-mental computation concepts: iterations, comparisons, functions, and vectors. Also, you will have an opportunity to write code that catches errors and throws exceptions. All work should be pre-graded in the labs and turned in to eCampus by the deadline. For programs, you…

Rate this product

You’ll get a: zip file solution

 

Description

Rate this product

Objectives: This assignment gives you some experience with writing C++ programs that use funda-mental computation concepts: iterations, comparisons, functions, and vectors. Also, you will have an opportunity to write code that catches errors and throws exceptions.

All work should be pre-graded in the labs and turned in to eCampus by the deadline. For programs, you need to turn in only the source code (not object or executable files). Your code will be tested using a g++ compiler. Therefore, you can develop your program in Visual Studio or Xcode, but make sure your code also compiles using g++ and runs on a Linux machine.

  1. (5 points) Create a text file, called README, in which you provide:

Your first name, last name, UIN, section number, user name, e-mail address State the Aggie Honor statement:

I certify that I have listed all the sources that I used to develop the solutions and code to the submitted work.

On my honor as an Aggie, I have neither given nor received any unautho-rized help on this academic work.

Your Name Date

List any resources used such as webpages titles and URLs. Do not mention the textbook and discussions with the Instructor, TA, or Peer Teachers. Describe in details the type of help you have obtained from each resources.

List any known problems with the assignment you are turning in. For example, if you know your code does not run correctly, state that. This should be a short explanation.

Write how you tested your programs for correctness and used exceptions for the error handling. Submit to eCampus an electronic version of the README file along with C++ code for the

problems listed below and a hard copy to your TA.

  1. (Lab 30 points) Complete the drills 1, 2, 3, pp. 297 and 298.

The C++ code for the above problems should be completed during the lab time, and presented to your TA or PTs before submitting to eCampus.

1

2

Important: A file name should correspond to the exercise number, e.g. LastName_UIN_D1-p297.cpp where LastName is your last name and UIN is your UIN number.

  1. (35 points) Write a program that computes the sequence of Fibonacci numbers. The formula for generating the next Fibonacci number is: Fn = Fn 1 + Fn 2, where F1 = 1 and F2 = 2. For example, F3 = F2 + F1 = 2 + 1 = 3. You will notice that at some point Fibonacci numbers are too large and they do not fit in type int. This is called the integer overflow. When they become negative (or non-increasing), stop the program. Please use three different functions, one for each type.

How many Fibonacci numbers fit in type int? What is the value of the largest one? How many Fibonacci numbers fit in type long? What is the value of the largest one?

How many Fibonacci numbers fit in type long long? What is the value of the largest one?

Interesting note: “13 year old makes solar power breakthrough by harnessing the Fibonacci’s se-

quence”, see

http://inhabitat.com/13-year-old-makes-solar-power-breakthrough-by-harnessing-the-fibonacci-sequence/

  1. (20 points) Write a recursive function decimal_to_octal(int n). This function should take a non-negative integer and return its octal form. Test the function in main using integers. Use the prefix 0 when you display a number in the octal form. Write in the README file about what

3

you have learned by writing this assignment and what results of your testing are. Write also about your (possible) problems, errors or mistakes.

  1. (40 points) Reverse the order of elements in a vector of integers using two functions:

    1. The first function takes the input vector a and return a vector b with the input data but in the reverse order, e.g. input: 1; 2; 3 and output 3; 2; 1.

    1. The second function is a recursive one and it reverses the input data in place (without using an additional vector).

Test the first and second algorithm using the same vector and compare results.

Important: A file name should correspond to the assignment number and exercise number, e.g.

LastName_UIN_A4-Ex5.cpp.

Submit all the files together as a zip/tar file to eCampus for grading.

4

Assignment-4 Solution
$30.00 $24.00