Simple Programs-Introduction to Computer Programming-Assignment, Exercises of Computer Engineering and Programming

This assignment was given by Dr. Jyoti Lokesh at Biju Patnaik University of Technology, Rourkela for Computer Programming course. It includes: Maximum, Charge, Program, Outputs, Inputs, Series, Pairs, Integers, Parameter, Side, Floating, Point

Typology: Exercises

2011/2012

Uploaded on 07/13/2012

ekvir
ekvir 🇮🇳

4

(1)

35 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMPUTER PROGRAMMING LAB
BONUS ASSIGNMENT(attempt any 20 questions)
1. A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage
charges an additional $0.50 per hour for each hour or part thereof in excess of three
hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car
parks for longer than 24 hours at a time. Write a program that calculates and prints the
parking charges for each of three customers who parked their cars in this garage
yesterday. You should enter the hours parked for each customer. Your program should
print the results in a neat tabular format and should calculate and print the total of
yesterday's receipts. The program should use the function calculateCharges to
determine the charge for each customer.
Your outputs should appear in the following format:
2. Write a function multiple that determines for a pair of integers whether the second is a
multiple of the first. The function should take two integer arguments and return true if
the second is a multiple of the first, false otherwise. Use this function in a program that
inputs a series of pairs of integers.
3. Write a program that inputs a series of integers and passes them one at a time to function
even, which uses the modulus operator to determine whether an integer is even. The
function should take an integer argument and return true if the integer is even and false
otherwise.
4. Write a function that displays at the left margin of the screen a solid square of asterisks
whose side is specified in integer parameter side. For example, if side is 4, the function
displays the following:
Car Hours Charge
1 1.5 2.00
2 4.0 2.50
3 24.0 10.00
TOTAL 29.5 14.50
****
****
****
****
5. Modify the function created in question no. 4 to form the square out of whatever
character is contained in character parameter fillCharacter. Thus, if side is 5 and
fillCharacter is #, then this function should print the following:
#####
#####
#####
#####
#####
6. Write a program that inputs three floating-point numbers and passes them to a function that
returns the smallest number.
7. (Perfect Numbers) An integer is said to be a perfect number if the sum of its factors,
including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect
number, because 6 = 1 + 2 + 3. Write a function perfect that determines whether
docsity.com
pf3
pf4

Partial preview of the text

Download Simple Programs-Introduction to Computer Programming-Assignment and more Exercises Computer Engineering and Programming in PDF only on Docsity!

COMPUTER PROGRAMMING LAB

BONUS ASSIGNMENT(attempt any 20 questions)

  1. A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday's receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format:
  2. Write a function multiple that determines for a pair of integers whether the second is a multiple of the first. The function should take two integer arguments and return true if the second is a multiple of the first, false otherwise. Use this function in a program that inputs a series of pairs of integers.
  3. Write a program that inputs a series of integers and passes them one at a time to function even, which uses the modulus operator to determine whether an integer is even. The function should take an integer argument and return true if the integer is even and false otherwise.
  4. Write a function that displays at the left margin of the screen a solid square of asterisks whose side is specified in integer parameter side. For example, if side is 4, the function displays the following: Car Hours Charge 1 1.5 2. 2 4.0 2. 3 24.0 10. TOTAL 29.5 14.




  1. Modify the function created in question no. 4 to form the square out of whatever character is contained in character parameter fillCharacter. Thus, if side is 5 and fillCharacter is #, then this function should print the following:
  1. Write a program that inputs three floating-point numbers and passes them to a function that returns the smallest number.
  2. (Perfect Numbers) An integer is said to be a perfect number if the sum of its factors, including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect number, because 6 = 1 + 2 + 3. Write a function perfect that determines whether

parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect.

  1. (PrimeNumbers) An integer is said to be prime if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. a. Write a function that determines whether a number is prime. b. Use this function in a program that determines and prints all the prime numbers between 2 and 10,000.
  2. (Reverse Digits) Write a function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367.
  3. The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the numbers. Write a function gcd that returns the greatest common divisor of two integers.
  4. Write a function qualityPoints that inputs a student's average and returns 4 if a student's average is 90100, 3 if the average is 8089, 2 if the average is 7079, 1 if the average is 6069 and 0 if the average is lower than 60.
  5. Write a program that simulates coin tossing. For each toss of the coin, the program should print Heads or Tails. Let the program toss the coin 100 times and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads. [Note: If the program realistically simulates the coin tossing, then each side of the coin should appear approximately half the time.]
  6. Write function distance that calculates the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double.
  7. Write a C++ program that prompts the user for the radius of a circle then calls inline function circleArea to calculate the area of that circle.
  8. Write a complete C++ program with the two alternate functions specified below, of which each simply triples the variable count defined in main. Then compare and contrast the two approaches. These two functions are a. function tripleByValue that passes a copy of count by value, triples the copy and returns the new value and b. function tripleByReference that passes count by reference via a reference parameter and triples the original value of count tHRough its alias (i.e., the reference parameter).
  9. Write a program that uses a function template called min to determine the smaller of two arguments. Test the program using integer, character and floating-point number arguments.
  10. Write a program that uses a function template called max to determine the largest of three arguments. Test the program using integer, character and floating-point number arguments.
  11. ( Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of alternativesPlease type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your

The sum is: 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 d. Further requirements: i. Create three functions:

  1. readArray with void return and one 2D array argument
  2. printArray with void return and one 2D array argument
  3. sumArray with void return and three 2D array arguments
  4. Write a myStrlen function which is the same as the library strlen function. Assume the prototype is int myStrlen(char a[]); int myStrlen(char* a);
  5. Write a function which shortens a string to n characters. If the string is already shorter than n, the function should not change the string. Assume the prototype is void truncate(char a[], int n);
  6. Write a function which capitalizes the first letter in every word. Assume the first letter is any letter at the beginning or preceded by a blank. All other letters should be turned into lowercase. You can use the library toupper and tolower functions. Assume the prototype is void capitalizeWords(char a[]);
  7. Write a function, deleteChar, which deletes any occurrence in the first argument, a, of the single character which is the second argument, c. Assume the prototype is void deleteChar(char a[], char c);

IMPORTANT INSTRUCTIONS:

  1. Read the problems carefully.
  2. For submission make a folder named your name and Reg. No. , paste all the programs in it. The file names must be the question numbers.
  3. Submission date and time is fixed, it will not be extended.
  4. Copy cases will get negative marks and it will badly affect your grades.