C++ Programming
- Write a program to print Hello, World on the standard output.
- Write a program that uses the multiplication operator, *, to print the product.
- Program to use
a separate statement to print each operand. - Write a program that uses a while to sum the numbers from 50 to 100.
- write a while that prints the numbers from ten down to zero.
- Write a program that prompts the user for two integers. Print each number in the range specified by those two integers.
- What are the differences between int, long, long long, and short?
- To calculate a mortgage payment, what types would you use for the rate, principal, and payment? Explain why you selected each type.
- Determine the type of each of the following literals. Explain the differences among the literals in each of the four examples:
- What, if any, are the differences between the following definitions: int month = 9, day = 7; int month = 09, day = 07;
- What values do these literals represent? What type does each have? (a) “Who goes with F\145rgus?\012” (b) 3.14e1L (c) 1024f (d) 3.14L
- Using escape sequences, write a program to print 2M followed by a newline. Modify the program to print 2, then a tab, then an M, followed by a newline.
- Explain the following definitions. For those that are illegal, explain what’s wrong and how to correct it.
(a) std::cin >> int input_value;
(b) int i = { 3.14 };
(c) double salary = wage = 9999.99;
(d) int i = 3.14; - Write a program to calculate the highest two numbers in an array with length n, and print these numbers with their indexes.
- Write a C++ program to change every letter in a given string with the letter following it in the alphabet (i.e. a becomes b, p becomes q, z becomes a).
- Write a C++ program to find the largest word in a given string.
- Write a C++ program to count all the characters, blank spaces and words in a given string.
- Write a C++ program to find a word in a given string that has the highest number repeated letters.
What are the differences between int, long, long long, and short? Between an unsigned and a signed type? Between a float and a double?
Short uses less memory and than int, long and long long. Minimum size of short and int is 16 bits, long has 32 bits, and long long has 64 bits. In C language the main difference is their size and range. Short is of 2 bytes and it’s value is from -32,768 to 32,767, int is of 4 bytes and its value is from -2,147,483,648 to 2,147,483,647, Long is of 4 bytes and it’s value is from -2,147,483,648 to 2,147,483,647 and long long is of 8 bytes and it’s value is from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
A signed variable can hold both positive and negative values. An unsigned variable can only hold positive integers. Both signed and unsigned can be applied to short, int, char and long. We can use cast to convert from signed to unsigned type and from unsigned to signed type.
Float and double both are used to represent floating point numbers or decimal digits. Size of the float is 32 bits and for double it is 64 bits. Float has 7 decimal digits precision whereas double has 15 digits precision.