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

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 .200. 157. ! is the factorial. 135 Task 5 145 is a curious number. For example If n=5 and random numbers are 110. 154. as 1! + 4! + 5! = 1 + 24 + 120 = 145.e. You are required to tell that in how many and which random numbers x occurs as a digit.300. Take another input x . Max value of n can be 999. 500. 299 And x =3 Then your program should output that 3 occurs in one number i.400. Task 4 Make a program to store n random numbers where n is a constant variable in your code. Bonus Question Bonus part: Can you calculate time taken by your programs (Task 1 to Task 5) given that n varies as 100. Max value of n can be 999. Print out all the curious numbers less than n where n is a number entered by the user. making sure that x consists of only one digit.Max value of n can be 999. 135.

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

Sign up to vote on this title
UsefulNot useful