Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Assignment of advanced Computer Programming

Question 1.

Write a c++ class called 'student' with

Data members:

name(string type),

marks1,marks2 (integer type)

And member functions:

calc_average() to calculate the average note and disp() to display the name and average
mark

Then write a program that uses the above class to create an array of 5 students. The program asks the
user to enter the name and marks of each student from the keyboard and then displays the name and
average mark of each student on different lines [6]

Question 2.
Define a class BOOK with the following specifications :
Private members of the class BOOK are
BOOK NO                integer type
BOOKTITLE             20 characters
PRICE                     float (price per copy)
TOTAL_COST()        A function to calculate the total cost for N number of copies where N is passed to the
function as argument.
Public members of the class BOOK are
INPUT()                   function to read BOOK_NO. BOOKTITLE, PRICE
PURCHASE()            function to ask the user to input the number of copies to be purchased. It invokes
TOTAL_COST() and prints the total cost to be paid by the user.
Question 3.
Write a Program which allows the user to input an integer value for a variable name Limit [2].
Based on the input value, the program should perform the following tasks:

• Check whether the value entered by the user falls within the range from 10 to 150. (10 and
150 included in the given range.) [2]

Display those numbers which are divisible by both 3 and 5 in the range from 1 up to the Limit.
[2]
Calculate and display the sum of those numbers which are divisible by either 3 or 5. [3]
Final task will be to count and display those numbers which are not divisible by 3 or5. [3]

For example if user enters Limit =21


Numbers which is divisible by both 3 and 5 is 15
Numbers which are divisible by either 3 or 5 = 3, 5, 6, 9, 10, 12, 18, 20, 21 ( as 15 is divisible by
both 3 and 5, so it is not included) Sum will be = 3+5+6+9+10+12+18+20+21= 104
Number which are not divisible by 3 or 5 = 1, 2, 4, 7, 8, 11, 13, 14, 16, 17, 19. And their sum will
be 1+ 2 + 4 + 7+ 8 +11+ 13+14 + 16+17 + 19 = 112

Question 4.

Write a recursive function that computes and returns the sum of all elements in an
array, where the array and its size are given as parameters.

//return the sum of all elements in a[]


int findsum(int a[], int n)
Question 5.

You might also like