Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

Homework

Determine the value, true or false, of each of the following Boolean expressions. Assume the following two declarations have been made:

int count = 0, limit = 10, x, y;

1. (count == 0) && (limit < 20)

2. count == 0 && limit < 20

3. (limit > 20) || (count < 5)

4. !(count == 12)

5. (count == 1) && (x < y)

6. (count < 10) || (x < y)

7. !( ((count < 10) || (x < y)) && (count >= 0) )

8. ((limit / count) > 7) || (limit < 20)

9. (limit < 20) || ((limit/count) > 7)

10. ((limit/count) > 7) && (limit < 0)

11. (limit < 0) && ((limit / count) > 7)

12. (5 && 7) + (16) (answer is true)

13.) Write an if-else statement that ouputs the word Solvent, decreases the value of savings by expenses, and sets the value of expenses to 0, provided the savings is at least as large as the expenses. If, however, savings is less than expenses, the if-else statement simply outputs the word Bankrupt and does not change the value of any variables. The variables, expenses and savings, are both float.

14.) Write an if-else statement that outputs the word Warning provided that the value of the variable temperature is greater than or equal to 100, or the value of the variable pressure is greater than or equal to 200, or both. Otherwise, the if-else statement outputs the word OK.

15.) If 0 is considered false and all other integer numbers are considered true in C++, what is the output of the following cout statements? You can assume that x is set up in the program as an integer and has a value.
a.) if (x=0)
cout << "0 is true" << endl;
else
cout << "0 is false" << endl;

b.) if (1)
cout << "1 is true" << endl;
else
cout << "1 is false" << endl;
c.) if (-1)
cout << "-1 is true" << endl;
else
cout << "-1 is false" << endl;

16.) What output will be displayed from the following code if int x = 2;
cout << "Start" << endl;
if (x <= 3)
if (x!= 0)
cout << "Hello from the second if" << endl;
else
cout << "Hello from the else" << endl;
cout << "End" << endl;
cout << "Start again" << endl;
if (x > 3)
if (x!= 0)
cout << "Hello from the second if" << endl;
else
cout << "hello from the else" << endl;
cout << "End Again" << endl;

17.) What will be displayed from the following code if extra = 2, if extra = -37, and if extra = 0?
if ( extra < 0)
cout << "Small" << endl;
else if (extra == 0)
cout << "Medium" << endl;
else
cout << "Large" << endl;

18.) What output will be displayed from the following code if x =1, if x=3, if x=2, and if x =4?
switch (x+1)
{
case 1: cout << "Roast Beef" << endl; break;
case 2: cout << "Roast Worms" << endl; break;
case 3: cout << "Chocolate ice cream" << endl;
case 4: cout << "Onion ice cream" << endl; break;
default: cout << "Bon Appetit" << endl;
}

19.) What output is produced by the following code?
a.) int x = 10;
while (x > 0)
{
cout << x << endl;
x = x - 3;
}
b.) int x = 10;
do
{
cout << x << endl;
x = x - 3;
} while (x > 0);

c.) int x = -42;
do
{
cout << x << endl;
x = x - 3;
} while (x > 0);

d.) int x = 10;
while (x > 0)
{
cout << x << endl;
x = x + 3;
}
e.) int count = 3;
while (count-- > 0)
cout << count << " ";

f. ) int count = 3;
while (--count > 0)
cout << count << " ";

g.) int n = 1;
do
{
cout << n<< " ";
} while (n++ <= 3);

h.) int n = 1;
do
{
cout << n << " ";
} while( ++n <= 3);

j.) for (int count = 1; count < 5; count ++)
cout << (2 * count) << " ";

k.) for (int n = 10; n > 0; n = n- 2)
{
cout << "Hello ";
cout << n << endl;
}

l.) for (float sample = 2; sample > 0; sample -= 0.5)
cout sample << " ";

20.) Rewrite the following loops as for loops:
a.) int i = 1;
while (i <= 10)
{
if (i < 5 && i != 2)
cout << ‘X';
i ++;
}

b.) int i = 1;
while (i <= 10)
{
cout << ‘X';
i += 3;
}

c.) int m = 100;
do
{
cout << ‘X';
m += 100;
} while (m < 1000);

21.) Code a C++ loop that will write the word "Hello" to the screen 10 times.

22.) Code a loop that will read in a list of even numbers (such as 2, -4, 8, 6) and compute the total of the numbers in the list. The list is ended with a sentinel value so you must decide what would be a good sentinel value and declare it as such before the loop.

23.) What will print as a result of the following nested loops?
for (int n = 1; n <= 3; n++)
for (int m = 5; m >= 1; m--)
cout << n << " times " << m << " = " << n*m << endl;

24.) Code two nested loops in C++ that will produce the following output:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

25.) Write a function prototype and a function definition for a function that takes one argument of type float and returns the character value ‘P' if the argument is positive and returns ‘N' if the argument is zero or negative.
26.) Write a function definition for a function called even that takes one argument of type int and returns a bool value. The function returns true if the argument is an even number. Otherwise, it returns false.

27.) Write a function definition for a function called in_order that takes three arguments of type int and returns true if the arguments are in ascending order. Otherwise it returns false. For example, in_order(1,2,3) and in_order(1,2,2) return true. And in_order(1,3,2) returns false.

28.) What is the output produced by the following code segment?
#include
char mystery (int,int); what is this called???
int main ()
{
cout << mystery(10,9) << "ow" << endl;
return 0;
}
char mystery (int first, int second)
{
if (first >= second)
return ‘W';
else
return ‘H';
}

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91875019
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in C/C++

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As