Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will...

12
1 | Page “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoplesGood Luck, Programming Hard! Sir Syed University of Engineering & Technology Karachi Department of Computer Science Assignment of Programming Fundamentals Course Code: (CS-116) Prepared By: Sallar Khan Note: Deadline for submission of this assignment will be 8 th May-2017. Copied assignment will be Rejected directly without any notification. Similar assignment of your colleague will be considered as Copied as well. Make your programs as simple as you can. Try to use appropriate topic according to the question given. Usage of comments will be appreciated. Every student have to use their firstname,lastname, rollno, instead of their desired variables. Unique variable names will be appreciated. Usage of new data types will be highly appreciated.

Transcript of Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will...

Page 1: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

1 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Sir Syed University of Engineering & Technology

Karachi

Department of Computer Science

Assignment of Programming Fundamentals

Course Code: (CS-116)

Prepared By: Sallar Khan

Note:

Deadline for submission of this assignment will be 8th –May-2017.

Copied assignment will be Rejected directly without any notification.

Similar assignment of your colleague will be considered as Copied as well.

Make your programs as simple as you can.

Try to use appropriate topic according to the question given.

Usage of comments will be appreciated.

Every student have to use their firstname,lastname, rollno, instead of their desired variables.

Unique variable names will be appreciated.

Usage of new data types will be highly appreciated.

Page 2: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

2 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q1. Write a program that stores monthly rainfall amounts in an array. The program then

displays the monthly rainfall amounts, the total annual rainfall amount, the average rainfall

amount, the highest rainfall amount, or the lowest rainfall amount First get the rainfall

amounts for the 12 months. Example:

Enter rainfall for month 1: 12.5

Enter rainfall for month 2: 15

Next, display the following menu and wait for the user response. Repeat the menu display

and the calculation as long as the user is not typing 6. (The rainfall amounts should be

entered only once in the program before displaying the menu.)

1 Display monthly amounts

2 Display total amount

3 Display average amount

4 Display highest amount

5 Display lowest amount

6 End program

Enter your choice: 1

Use the following functions to calculate the amounts:

displayMonthly: displays the monthly rainfall amounts

displayTotal: displays the total rainfall amounts for the entire year

displayAverage: displays the average rainfall amounts during the year.

displayHigh: displays the month with the highest rainfall amount

displayLow: displays the month with the lowest rainfall amount.

Q2. Write a C++ program that will display if a students is pass or not in his exam.

(50% or more is pass). If the student is Pass than your program should display

which letter the student has obtained:

- 85% or more E for excellent

- 75% or more but less than 85% O for Outstanding

- 65% or more but less than 75% G for good

- Less than 65% S for satisfactory

If however the student is Fail (below 50% marks) your program should display.

Whether the student should Resit or Redo depending on the following criteria.

- 33% or more Resit in exam

- Less than 33% Redo course.

Page 3: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

3 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q3. Write a C++ program in which user enter his NTS and FSc marks and your

program will help student in selection of university. Based on these marks

Student will be allocated a seat at different department of different

university.

University Name Departments Criteria

Oxford University IT Above 70% in Fsc. and 70 % in NTS

Electronics Engr: Above 70% in Fsc. and 60 % in NTS

Telecommunication Above 70% in Fsc. and 50 % in NTS

MIT IT 70% -60 % in Fsc. and 50 % in NTS

Chemical Engr: 59% – 50 % in Fsc. and 50 % in NTS

Computer Engr: Above 40% and below 50 % in Fsc. and

50 % in NTS

Note: Use Nested if structure to solve the problem. Don’t use logical operators.

Violation of this condition will result in zero marks.

Q4. Write a program that continually calculates the cube of a number until the user

enters a number that is divisible by both 2 and 3.

Expected Output:

Enter a number: 3

Cube of 3 is: 27

Enter a number: 2

Cube of 2 is: 8

Enter a number: 12

Q5. Write a program that calculates the total point earned by a football team over a series of

games and calculate the average of team. It allows the user to enter the series of game points,

then -1 to signal the end of the list.

Q6. An electronics company sells circuit boards at 40% profit. Write a program

that will calculate the selling price of a circuit board that costs $12.67.

Display the result on the screen

Q7. Write a C++ Program to calculate Sales tax.

Q8. Write a C++ program to print the bill.

Take the units(programology) consumed

Accordingly calculate amount

Page 4: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

4 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

for 1st 100 units @ 1Rs.(any currency)/unit

for next 100 units @ 2 Rs./unit

for next 100 units @ 3 Rs./unit

for next 200 units @ 4 Rs./unit

for next units @ 5 Rs./unit

tax to be added in final amount @ 10%.

Meter charge 50 Rs. extra.

Print the bill.

Q9. Write a C++ program which takes the price of bakery items ranging from 0-999

if you enter PKR 1-200 it should show cakes

if PKR 200 – 400 SHOW BISCUITS

if PKR 400- 700 show miscellaneous

if PKR 700 – 999 show ice cream your program to should run 3 times using

While loop in the end also take the average of all items price

Q10. Write a C++ program that will ask user to enter two integral numbers. The numbers

should be swapped without using any third variable. Your code should be able to do the same

process for 30 cycles. It should also show the swapped numbers at the each cycle.

Q11. Write a C++ program for Electricity Bill Statement (EBS). The EBS takes units

consumed from consumer and calculates; Electricity Charges (EC) using provided criteria:

001 – 100 units @ Rs. 2.00/- (per unit) 100 – 200 units @ Rs. 3.50/- (per unit) 200 and more

units @ Rs. 4.50/- (per unit) General sale tax which is the 10% of the EC. Amount due (EC +

Gen. sale tax) what, if we want to tell EBS to 1000 customers.

Q12. FBR Pakistan announces the tax policy for 2015-2016. As per the Finance Act passed by

Government of Pakistan, following slabs and income tax rates shall be applicable for salaried

persons and salaried class for the year 2015-2016: 1. Where the taxable salary income does

not exceed Rs 400,000, the rate of income tax is 0%; 2. Where the taxable income exceeds

Rs 400,000 but does not exceed Rs 500,000, the rate of income tax is 2% of the amount

exceeding Rs 400,000. 3. Where the taxable income exceeds Rs 500,000 but does not exceed

Page 5: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

5 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Rs 750,000, the rate of income tax is Rs. 2,000 + 5% of the amount exceeding Rs 500,000. 4.

Where the taxable income exceeds Rs 750,000 but does not exceed Rs 1,400,000,the rate of

income tax is Rs 14,500 + 10% of the amount exceeding Rs 750,000. 5. For the rest of cases,

the tax rate is Rs.17,500+20% of the amount exceeding Rs. 750,000. Being computer

programmer, you have to write a program that will calculate the tax of salaried persons as per

given policy.

Page 6: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

6 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q13. Write a program that asks the user to enter a number of seconds.

– There are 60 seconds in a minute. If the number of seconds entered by the user is greater than

or equal to 60, the program should display the number of minutes in that many seconds.

– There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater

than or equal to 3,600, the program should display the number of hours in that many seconds.

– There are 86,400 seconds in a day. If the number of seconds entered by the use is greater or

equal to 86,400, the program should display the number of days in that many seconds. Using

same method also calculate it for years and month.

Q14. A software company sells a package that retails for $99. Quantity discounts are given

according to the following table:

Quantity Discount :

10-19 20%

20-49 30%

50-99 40%

100 or more 50%

Write a program that asks for the number of units sold and computes the total cost of the

purchase.

Input validation: Make sure the number of units is greater than 0.

Q15. Write a C++ program to check triangle by entering 3 angles.

Q16. Write a C++ program to find ASCII Code for Characters, numbers and symbols.

Q17. Write a C++ programs to determine transpose of a matrix with function and

without function.

Page 7: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

7 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q18. Write a C++ program which asks the user several questions and selects a car for them.

The questions are

1) do you have children;

2) do you have lots of money;

3) do you like trucks.

Porsche: have no children, have lots of money, don’t like trucks Yukon: have no children,

have lots of money, like trucks Civic: have no children, have little money Villager: have

children, have lots of money, don’t like trucks Explorer: have children, have lots of

money, like trucks Sentra: have children, have little money.

Q19. An Internet service provider has three different subscription packages for its customers:

Package A: for $9.95/month, 10 hours of access are provided. Additional hours are

$2.00/hour.

Package B: for $14.95/month, 20 hours of access are provided. Additional hours are

$1.00/hour.

Package C: for $19.95/month, unlimited access is provided.

Write a program that calculates a customer’s monthly bill. It should ask which package

the customer has purchased and how many hours were used. It should then display the

total amount due.

Input validation: be sure the user only selects package A, B, or C. Also, the number of

hours used in a month cannot exceed 744.

Q20. C++ Program for Decimal to Hexadecimal Conversion.

Q21. To make telephone numbers easier to remember, some companies use letters to show

their telephone number. For example, using letters, the telephone number 438-5626 can be

shown as GET LOAN. In some cases, to make a telephone number meaningful, companies

might use more than seven letters. For example,

225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that

prompts the user to enter a telephone number expressed in letters and outputs the

corresponding telephone number in digits. If the user enters more than seven letters, then

process only the first seven letters. Also output the A¸S (hyphen) after the third digit. Allow

the user to use both uppercase and lowercase letters as well as spaces between words.

Moreover, your program should ˘process as many telephone numbers as the user wants.

Page 8: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

8 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q22. Write a C++ Program to display Box shape using for loop.

Q23. Write a program that displays the following menu:

1. Calculate the area of a circle

2. Calculate the area of a rectangle

3. Calculate the area of a triangle

4. Quit

Enter your choice (1-4):

If the user enters 1, the program should ask for the radius of the circle and then display its

area. Use the following formula: area = PI * r * r.

Use 3.14159 for Pi and the radius of the circle for r. If the user enters 2, the program

should ask for the length and width of the rectangle and then display the rectangle’s

area. Use the following formula: area = length * width

If the user enters 3, the program should ask for the length of the triangle’s base and its

height, and then display its area. Use the following formula:area = base * height * 0.5 If

the user enters 4, the program should end.

Input validation: Display an error message if the user enters a number outside the range of 1

– 4 when selecting an item from the menu. Do not accept negative values for the circle’s

radius, the rectangle’s length or width, or the triangle’s base or height.

__________________SECTION# (01) ENDS HERE_____________________

Page 9: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

9 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q24. Write a program that asks for the names of three runners and the time it took each of

them to finish the race. The program should display who came in first,second, and third

place.

Input validation: only accept positive numbers for the times.

Q25. Write a program that asks for the number of calories and fat grams in a

food. The program should display the percentage of calories that come from fat. If the

calories from fat are less than 30% of the total calories of the food, it should also display a

message indicating that the food is low in fat.

One gram of fat has 9 calories, so

Calories from fat = fat grams * 9

The percentage of calories from fat can be calculated as:

Calories from fat/total calories Input validation: Make sure the number of calories and fat grams

are not less than 0.Also, the number of calories from fat cannot be greater than the total number

of calories. If that happens, display an error message indicating that either the calories or fat

grams were incorrectly entered.

Q26. Sallar khan from SSUET doing CSD bought 600 shares of stock at a price of $21.77 per

share. He must pay his stock broker a 2% commission for the transaction. Write a program

that calculates the display the following:

The amount paid for the stock alone (without the commission)

The amount of the commission

The total amount paid.

Q27. Write a program that computes the tax and tip on restaurant bill for a patron with a

$44.50 meal charge. The tax should be 6.75% of the meal cost. The tip should be 15% of the

total after total after adding the tax. Display the meal cost, tax amount, tip amount and total

bill on the screen.

Page 10: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

10 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q28. Write a C++ program to Find Largest Element Using Dynamic Memory Allocation.

Q29. You customer wants you to design and then build an online store. While interviewing the

customer you collect the following information:

Track products and related information. To do: extract details from interview notes.

Track customers, especially what the customer owes. To do: extract details (i.e. other

information to track) from interview notes.

Abilities the customer wants in the system:

Identify a product that will be for sale. You should read in the name, model number,

wholesale cost, and retail cost for the product.

Enter a new customer. You should read in the customer name and ID.

Take a shipment of new products. Read in the model number and quantity. If you don't

know what the product is that you're getting, reject the shipment, otherwise add that to

inventory.

Let a customer buy something. The customer ID, product model number, and quantity

should be taken as input.

If there is sufficient quantity of the product on hand, then the customer should be charged

that amount and the product be deducted from inventory.

If there is not sufficient quantity, the sale should be rejected.

Let a customer make a payment. Read in the customer ID and the amount of payment. It's

OK for customers to have a positive balance, but they cannot make negative payments.

Find out about a customer: enter a customer ID number, and print out the customer's

name, current balance, and a list of what the customer has previously purchased.

Find out about a product: enter a model number and get the name of the product, the

amount that has already been sold, and the amount in inventory.

Print lists of all information about all customers and all products.

Q30. What will be output of following program?

#include<stdio.h>

int main(){

char far *p =(char far *)0x55550005;

char far *q =(char far *)0x53332225;

*p = 80;

(*p)++;

printf("%d",*q);

return 0;

}

Page 11: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

11 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q31. What will be output of following program?

#include<stdio.h>

#include<string.h>

int main(){

char *ptr1 = NULL;

char *ptr2 = 0;

strcpy(ptr1," c");

strcpy(ptr2,"questions");

printf("\n%s %s",ptr1,ptr2);

return 0;

}

Q32. What will be output of following program?

#include<stdio.h>

#include<string.h>

int main(){

int a,b,c,d;

char *p = ( char *)0;

int *q = ( int *q)0;

float *r = ( float *)0;

double *s = 0;

a = (int)(p+1);

b = (int)(q+1);

c = (int)(r+1);

d = (int)(s+1);

printf("%d %d %d %d",a,b,c,d);

return 0;

}

Q33. Write a C++ program character without using format specifier.

Q34. Write a C++ program to count vowels and consonants in a string using pointer.

Q35. Write a program to swap two numbers using pointers.

Q36. Write a C++ program to calculate length of the string using recursion.

Page 12: Sir Syed University of Engineering & Technology Karachi ... | P a g e “Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples” Good

12 | P a g e

“Intelligent students will use Books; Average students will use Internet, while Poor one copy peoples”

Good Luck, Programming Hard!

Q37. Write a C++ program to read age of 15 people and count total Baby age, School age and

Adult age.

Q38. Write a C++ Program to calculate total elapsed time by program/ function.

Q39. Serendipity Booksellers has a book club that awards points to its customers based on the

number of books purchased each month. The points are awarded as follows:

-If a customer purchases 0 books, 0 points are earned.

-If a customer purchases 1 book, 5 points are earned.

-If a customer purchases 2 books, 15 points are earned.

-If a customer purchases 3 books, 30 points are earned.

-If a customer purchases 4 or more books, 60 points are earned.

Write a program that asks the user to enter the number of books that he or she has

purchased this month and then display the number of points awarded.

Q40-Create a change-counting game that gets the user to enter the number of coins required to

make exactly one dollar. The program should ask the user to enter the number of pennies,

nickles, dimes, and quarters. If the total value of the coins entered is equal to one dollar, the

program should congratulate the user for winning the game. Otherwise, the program should

display a message indicating whether the amount entered was more than or less than one dollar

Q41. If scientists know the wavelength of an electromagnetic wave, he or she can determine

what type of radiation it is. Write a program that asks for the wavelength of an

electromagnetic wave in meters and then displays what the wave is according to the chart

below. (For example, a wave with a wavelength of 1E-10 meters would be an X-ray.

__________________SECTION# (02) ENDS HERE_____________________