Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
69 views

Programming Assignment 2

The document provides 4 programming assignment questions for an introductory computer programming course. Question 1 asks students to write a function that checks the validity of two user-input numbers based on certain criteria and allows the user to play the game multiple times. Question 2 asks students to write a function that finds all right triangles with integer sides smaller than a given number N. Question 3 asks students to create an automated register for a bakery by tracking inventory and sales. Question 4 is a bonus question that asks students to swap two integers without using a temporary variable. The questions require skills like functions, loops, input/output, and error checking.

Uploaded by

ak47_uzii
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Programming Assignment 2

The document provides 4 programming assignment questions for an introductory computer programming course. Question 1 asks students to write a function that checks the validity of two user-input numbers based on certain criteria and allows the user to play the game multiple times. Question 2 asks students to write a function that finds all right triangles with integer sides smaller than a given number N. Question 3 asks students to create an automated register for a bakery by tracking inventory and sales. Question 4 is a bonus question that asks students to swap two integers without using a temporary variable. The questions require skills like functions, loops, input/output, and error checking.

Uploaded by

ak47_uzii
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ISE 103 Fundamentals of Computer Programming

Programming Assignment # 2
Deadline: Friday April 08, 2011 11:59 PM Submission: Using LMS Question# 1: Create a function in C/C++, which takes two numbers from user and checks their validity according to the following criteria. Provide a menu to user so that he/she can play the game for more than once using do while loop: a. The number should not be a prime number. b. Each number should be between 1 and 1000 c. The two numbers should not be divisible by each other. d. The difference of the two should not be less than 1. e. The addition of these two numbers should not exceed 1000. Provide proper customized error (reason for invalidity) checking if the above criteria is not met. Question#2: A right triangle can have three sides (b=base, p=perpendicular and h=hypotenuse) that are all integers. A triangle is said to be the right triangle if it fulfills the Pythagoras theorem. Write a function using nested loops to find out all right triangles where b, p and h are smaller than number N. Your function should take N as an argument (input). Also write a main program to test this function. Pythagoras theorem states: h2 = b2 + p2 Question#3: Create an automated register for a bakery. Create four integers and name them accordingly for four items (e.g. bread, eggs, milk and butter). Associate a variable to each item, indicating the amount of a particular item present in the bakery at the start of a day and assign each item a unit cost (e.g 1 bread = 40, 1 egg = 4, 1 liter milk = 34 and 1 kg butter = 25). The user sees a menu in the start that shows him the number of each item in the bakery. The user also has an option to sell any number of these items. Keep a track of the total sales the user makes. The user can view the remaining items and the total sale he has achieved (through menu option). When user wants to exit the program, he should see statistics of the items remaining and the total sales done. Also make sure to check for errors, wrong input and any other bugs in the program. Note: Your approach to solve this problem is important. Modular approach (using functions) will win more points.

Question#4 (Bonus Question): Swap two integers without using any other variable. Code to swap two variables using a temp variable follows: #include<stdio.h> int main(){ int temp=0;int a=3; int b=8; printf("The two numbers before swapping are:%d and %d\n",a,b); temp = a; a = b; b = temp; printf("The two numbers after swapping become:%d and%d\n",a,b); return 0; }

You might also like