Purchase Solution

How to use cout in C++ statements ?

Not what you're looking for?

Ask Custom Question

15. What is the output of the following statements? Suppose a and b are int variables, c is a double variable, and a = 13, b = 5, and c = 17.5.

a. cout <<a + b - c << endl; = 0.5
b. cout << 15 / 2 + c << endl; = 25
c. cout << a / static_cast<double>(b) + 2 * c << endl; = 37
d. cout << 14 % 3 + 6.3 + b / a << endl; = 8.6846153
e. cout << static_cast<int>(c) % 5 + a - b << endl; = 11
f. cout << 13.5 / 2 + 4.0 * 3.5 + 18 << endl; = 33.75

Would you please check my work to see if I did this correct. Thanks a lot!

Purchase this Solution

Solution Summary

The expert discusses several short examples of correct use of cout in different c++ statements.

Solution Preview

#include <iostream.h>
int main(){
int a,b;
double c;
a=13;
b=5;
c=17.5;
cout << a<< endl;// != 0.5
// a = 13, if you didn't miss something

cout << 15 / 2 + c << endl;// != 25
//15/2 = 7 (integer division) + 17.5 = 24.5

/*
lets look at an example using static_cast<>()

#include <iostream>
using namespace std;

int main() {
int j = 41;
int v = 4;
float m = j/v;
float d = ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Networking Questions

This quiz consists of some basic networking questions.

C++ Operators

This quiz tests a student's knowledge about C++ operators.