logo

Crowdly

Browser

Add to Chrome

met2502f25-a.sg

Looking for met2502f25-a.sg test answers and solutions? Browse our comprehensive collection of verified answers for met2502f25-a.sg at distance3.sg.digipen.edu.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

In C++ we read characters from the keyboard using global variable std::cin that encapsulates the standard input stream and is of a C++ standard library type std::istream. Here, std::cin is the fully qualified name of object cin that is defined in namespace std.

Both C and C++ define bitwise right shift binary operator >> with the syntax

lhs-integral-expression >> rhs-integral-expression

to shift the bits of left operand lhs-integral-expression to the right by the number of bits in right operand rhs-integral-expression.

Class type std::istream overloads bitwise right shift operator >> to read characters representing different types of values from an input stream. Format specification, which is the first parameter of function scanf is not required. Using overloaded operator >> instead of function scanf also allows us to read multiple values from the input stream in a single chained statement, as in the following example:

int x;

double y;

std::cin >> x >> y;

Supposing the user types characters into the standard input stream, write the exact text written by the following code fragment to the standard output stream.

int x;

double y;

std::cin >> x >> y;

std::cout << x+static_cast<int>(y);

View this question

In C++ we write characters to the console using global variable std::cout that encapsulates the standard output stream and is of C++ standard library type std::ostream. Here, std::cout is the fully qualified name of an object cout that is defined in namespace std.

Both C and C++ define bitwise left shift binary operator << with the syntax

lhs-integral-expression << rhs-integral-expression

to shift the bits of operand lhs-integral-expression to the left by the number of positions specified by operand rhs-integral-expression.

Class type std::ostream overloads the built-in behavior of bitwise left shift operator << to write characters representing different type of values to an output stream. Format specification, which is the first parameter of function printf is not required. Using overloaded operator << instead of function printf also allows us to write different values in a single chained statement, as in the following example:

char ch = 'c';

std::cout << "character: " << ch << std::endl;

std::endl represents a stream manipulator that inserts the end of line character into the standard output stream followed by the flushing of the standard output stream. You can keep using character '\n' as a more efficient alternative to insert a newline rather than stream manipulator endl. Inserting character '\n' into the output stream is more efficient since only a single character is inserted into the output stream without flushing the contents of the output stream's memory buffer. On the other hand, using stream manipulator endl makes C++ code portable [because we don't have to remember the newline character when a non-ASCII character set is used].

What is the result of compilation and execution of the following code? Type the exact output or type  if the code doesn't compile.

#include <iostream>

int main() {

cout << "Hello World!";

}

View this question

The preprocessor #include directive has the form #include <FILENAME>, where FILENAME is a string for the included header file.

Standard C library headers can be included in C++ source files exactly as in C source files. For example, both C and C++ source files can make references to functions printf, scanf, fprintf, and others by including header file <stdio.h>.

C++ also allows standard C library functions to be referenced using names qualified by namespace std. However, in that case, standard C library header filenames must be transformed by the following rule:

  1. the header file name no longer maintains the .h extension, and
  2. the header file name has to be preceded by character c.

For example, header file ctype.h becomes cctype.

Apply this rule to the following standard C library header filenames to match their corresponding C++ header file [so that functions declared in these standard C library headers can only be referenced in C++ code by qualifying their names with namespace std].

View this question

Want instant access to all verified answers on distance3.sg.digipen.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome