0% found this document useful (0 votes)
17 views4 pages

Assignment2B (Due On November 30)

The document outlines a series of C++ programming assignments, including tasks such as calculating average fuel consumption, checking number ranges, converting binary to decimal, and correcting code errors. It also includes programs for credit limit calculations, demonstrating pre- and post-decrementing, and using switch statements for various applications. Additionally, it mentions completing truth tables as part of the exercises.

Uploaded by

Zaeem Muzammil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Assignment2B (Due On November 30)

The document outlines a series of C++ programming assignments, including tasks such as calculating average fuel consumption, checking number ranges, converting binary to decimal, and correcting code errors. It also includes programs for credit limit calculations, demonstrating pre- and post-decrementing, and using switch statements for various applications. Additionally, it mentions completing truth tables as part of the exercises.

Uploaded by

Zaeem Muzammil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment Problems

1. Write a C++ program to calculate a bike’s average consumption from the


given total distance (integer value) traveled (in km) and spent fuel (in liters,
float number – 2 decimal points).
2. Write a C++ program that reads an integer and check the specified range
where it belongs using if-else-if. Print an error message if the number is
negative and greater than 80.
3. (Printing the Decimal Equivalent of a Binary Number) Input an integer (5
digits or fewer) containing only 0s and 1s (i.e., a “binary” integer) and print
its decimal equivalent. [Hint: Use the remainder and division operators to
pick off the “binary” number’s digits one at a time from right to left. Just as
in the decimal number system, in which the rightmost digit has a positional
value of 1, and the next digit left has a positional value of 10, then 100, then
1000, and so on, in the binary number system the rightmost digit has a
positional value of 1, the next digit left has a positional value of 2, then 4,
then 8, and so on. Thus the decimal number 234 can be interpreted as 4 * 1 +
3 * 10 + 2 * 100. The decimal equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1
* 4 + 1 * 8 or 1 + 0 + 4 + 8 or 13.]
4. Print the value 123.4567 with two digits of precision. What value is printed?
5. Print the floating-point value 3.14159 with three digits to the right of the
decimal point. What value is printed?
6. Identify and correct the errors in each of the following:
i) if ( gender == 1 )
cout<< "Woman" ;
else;
cout<< "Man" ;

ii) if ( a= 1 )
cout<< "a is equal to 1" ;
else
cout<< "a is not equal to 1" ;

iii) if ( ch == 1 );
cout<< "Lab" ;
else
cout<< "Tutorial" ;

iv) Write four different C statements that each adds 1 to integer variable x.
7. (Credit Limit Calculator) Develop a C++ program that will determine if a
department store customer has exceeded the credit limit on a charge account.
For a customer, the following facts are available:
a. Account number
b. Balance at the beginning of the month
c. Total of all items charged by this customer this month
d. Total of all credits applied to this customer's account this month
e. Allowed credit limit
The program should input each fact, calculate the new balance (= beginning
balance + charges – credits), and determine whether the new balance
exceeds the customer's credit limit. For those customers whose credit limit is
exceeded, the program should display the customer's account number, credit
limit, new balance and the message “Credit limit exceeded.” Here is a
sample input/output dialog:

8. (Predecrementing vs. Postdecrementing) Write a program that demonstrates


the difference between predecrementing and postdecrementing using the
decrement operator --.
9. (Dangling Else Problem) Determine the output for each of the following
when x is 9 and y is 11, and when x is 11 and y is 9. The compiler ignores
the indentation in a C program. Also, the compiler always associates an else
with the previous if unless told to do otherwise by the placement of braces
{}. Because, on first glance, you may not be sure which if an else matches,
this is referred to as the “dangling else” problem. We eliminated the
indentation from the following code to make the problem more challenging.
[Hint: Apply indentation conventions you have learned.]
a. if ( x < 10 )
if ( y > 10 )
cout<< "*****" ;
else
cout<< "#####" ;
cout<< "$$$$$" ;

b. if ( x < 10 ) {
if ( y > 10 )
cout<< "*****" ;
}
else {
cout<< "#####" ;
cout<< "$$$$$" ;
}
10.Write a C++ program to find maximum between two numbers using switch
statement.
11.Write a C++ program to find the day of the week using switch statement.
12.Write a C++ program to check whether an alphabet is a vowel or consonant
using switch statement.
13.Program to Calculate Grades according to your grading system using
switch statement. Total marks are supposed to be 100.
14. (Truth Tables) Complete the following truth tables by filling in each blank
with 0 or 1.

-------------------------------

You might also like