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

CS106 Programming Fundamentals Submission Instructions

Submission by email to raza.rehman@abasyn.edu.pk or razaurrehman@gmail.com Subject of the email should be CS106-PS4-YourName-RegNo No collaboration allowed. Due Date : 19th Nov 9 am You should send cpp files with names Task1.cpp, Task2.cpp in one zip file

Problem Set 4 (Arrays)


Task 1
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find that how many even, odd and prime values are there in first n Fibonacci Series elements, where n is a constant variable in your code. Max value of n can be 999.

Task 2
Find sum of all the primes less than n where n is a constant variable in your code. Max value of n can be 999.

Task 3
Make a program to store the years of birth of all the members of a class of size n where n is a constant variable in your code. You have to fill random data as years of birth but you have to make sure that the year of birth must be in the range of 1980 to 2000. Find out how many of your class fellows were born in a leap year http://en.wikipedia.org/wiki/Leap_year

Max value of n can be 999.

Task 4
Make a program to store n random numbers where n is a constant variable in your code. Take another input x , making sure that x consists of only one digit. You are required to tell that in how many and which random numbers x occurs as a digit. Max value of n can be 999. For example If n=5 and random numbers are 110, 154, 135, 157, 299 And x =3 Then your program should output that 3 occurs in one number i.e. 135

Task 5
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. ! is the factorial. Print out all the curious numbers less than n where n is a number entered by the user. Max value of n can be 999.

Bonus Question
Bonus part: Can you calculate time taken by your programs (Task 1 to Task 5) given that n varies as 100,200,300,400, 500. Can you draw a graph for time taken vs input size in Excel? ( you should email excel graph to me as well) Hint: time function can help you in time calculation

Tips &Tricks/ Advice/Recommendations/Additional References


Advice (taken from Section 4.10 of Bjarne Stroustrup, C++ Programming Language, 3rd Edition, 2000.)
1. Keep scopes small. 2. Dont use the same name in both a scope and an enclosing scope. 3. Declare one name (only) per declaration. 4. Keep common and local names short, and keep uncommon and nonlocal names longer. 5. Avoid similar-looking names. 6. Maintain a consistent naming style. 7. Choose names carefully to reflect meaning rather than implementation. 8. Use a typedef to define a meaningful name for a built-in type in cases in which the built-in type used to represent a value might change. 9. Use typedefs to define synonyms for types; use enumerations and classes to define new types. 10. Remember that every declaration must specify a type (there is no implicit int) 11. Avoid unnecessary assumptions about the numeric value of characters. 12. Avoid unnecessary assumptions about the size of integers. 13. Avoid unnecessary assumptions about the range of floating-point types. 14. Prefer a plain int over a short int or short or a long int or a long. 15. Prefer a double over a float or a long double. 16. Prefer plain char over signed char and unsigned char. 17. Avoid making unnecessary assumptions about the sizes of objects. 18. Avoid unsigned arithmetic. 19. View signed to unsigned and unsigned to signed conversions with suspicion. 20. View floating-point to integer conversions with suspicion. 21. View conversions to a smaller type, such as int to char, with suspicion. Another important thing, develop habit to declare and initialize the variable at the same time.

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