Concept explainers
Explanation of Solution
using namespace std;
include <#ioStream>
The preprocessor commands are processed by the preprocessor before the
#include <iostream>
using namespace std;
int main() {
(no errors)
int num1; num2;
The identifier num2 appears after the statement terminator semi-colon. Hence, the semicolon should be replaced by a comma. Correct statement;
int num, num2;
string str1;
(no errors)
cout << "Enter a string without any blanks in it ": ;
There is a colon which is intended to be part of the output string but appears after the string terminator double quotation marks. Correct statement:
cout << "Enter a string without any blanks in it :" ;
cin >> string
Multiple errors - instead of using the identifier str1, the data type string has been placed to receive the input. Also the statement terminator is missing. Correct statement:
cin >> str1;
cout << endl;
cout << "Enter two integers: ";
(no errors)
cin << num1, num2;
The first stream operator should be an extraction operator which is >> and the second stream extraction operator is missing altogether and a comma has been used instead. Correct statement:
cin >> num1 >> num2;
cout << endl;
(no errors)
return 0;
The return statement should be the last statement in any function and in this case, the main function...
Trending nowThis is a popular solution!
Chapter 2 Solutions
C++ Programming: From Problem Analysis to Program Design
- Create the following code in C++ DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will ask the user if he or she wishes to enter a different string or quit.arrow_forwardIs it true or false? A string cannot be stored in a char data type variable.arrow_forwardThe following C program requests four string from the user, sorts the four strings alphabetically and prints out the strings alphabetically as well as the string length. A typical usage input and output is shown below: Enter a string less than 50 characters in length: zebraEnter a string less than 50 characters in length: monkeyEnter a string less than 50 characters in length: baboonEnter a string less than 50 characters in length: apeape, [3]baboon, [6]monkey, [6]zebra, [5] Complete the following C program using the code provided. #include <stdio.h>#include <string.h> void swapstr(char *str1, char *str2); void main(void){ //line 1 int i = 0, j = 3; do { printf("Enter a string less than 50 characters in length: "); //line 2 i++; //line 3 //sort strings alphabetically //line 4 //line 5 //line 6 }//for j--; }//while //print sorted strings and its length //line 7 //line 8 }}//main void…arrow_forward
- A group of statements, such as the contents of a function, is enclosed inA) Braces {}B) Parentheses ()C) Brackets <>D) All of the above will doarrow_forwardFind errors in the following lines of c++ code assuming included header files. Write correct form with line number. 1. int main() 2. { 3. Int a=4.5 4. Char ch=’a’ 5. Int a++; 6. Cout<<”the value of a=’; 7. Cout>>a; 8. For( ; a<=5; ) 9. Cout<<a; 10. }arrow_forwardQuestion 9 nag.Write a program in C# that prompts the user to enter any string phrase and capitalizes the first letter of each word in the string. I need it to be user prompted, please! Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forward
- (Numerical) a. Write a C++ program that accepts an integer argument and determines whether the passed integer is even or odd. (Hint: Use the % operator.) b. Enter, compile, and run the program written for Exercise 8a.arrow_forward3. To use the string functions in C++, we must include the library: a) istream b) string ¢) math d) conioarrow_forwardPLEASE SOLVE THIS IN C++ CODE ONLY! PLEASE READ AND DO THE PROGRAM WITH ACCORDING TO THE CONDITIONS GIVEN. PLEASE ALSO WRITE THE USE OR FUNCTIONS OF EACH CODE USED BY INSERTING ITS USE EVERY LINE USING "//" A palindrome is a string that reads the same from front to back as it does from back to front, e.g., "racecar", "radar", "21012". Write a program that will identify whether a given line of input is a palindrome or not. Your program must also be able to determine the following sample inputs as palindromes, aside from identifying one-word inputs: Able was I 'ere I saw Elba. Madam, I'm Adam. A man, a plan, a canal, Panama. These samples require that your program must ignore spaces and punctuations, and consider uppercase and lowercase letters to be the same. Include necessary functions in your program to process the input. You can also use existing functions from the string library.arrow_forward
- 21.2 LAB: Remove spaces - functions Write a program that removes all spaces from the given input. Ex: If the input is: Hello my name is John. the output is: HellomynameisJohn. Your program must define and call the following function. The function should return a string representing the input string without spaces.remove_spaces (user_string) Use Python, please.arrow_forwardin C++ please For this problem you must create a program that accepts a line of English text as input. The string may contain spaces, so make sure you read the entire line of input. Next your program should count the occurrences of each letter of the English alphabet and determine which letter occurs most frequently in the string. Print this letter to the screen. If two letters tie for the most frequent count, break the tie by choosing the letter that occurs first in the alphabet. For example if the input string was "aabb", then your program should identify 'a' as the most frequently occurring letter. Finally, remove all occurrences of this most frequently occurring letter by replacing them with the '-' character, and print the final string to the screen. Sample Input aaaab Sample Output a ----b Simplifying Assumptions You may assume that all letters are lowercase You only need to count the letters of the alphabet (i.e. don't worry about counting special characters like punctuation,…arrow_forwardThis is a tic tac toe program i made. Help me debug it. This is in c programming. Here is the code: #include <stdio.h> /*int board[25] = { :,:,:,:,:, :,O,-,X,:, :,X,-,-,:, :,-,-,-,:,}*/ const NOUGHTS = 1;const CROSSES = 2;const BORDER = 3;const EMPTY = 0; const int ConvertTo25{9} = { 6,7,8, 11,12,13, 16,17,18}; void InitialiseBoard(int*board) { int index = 0; for (index = 0; index < 25; ++index) { board[index] - BORDER; } for (index = 0; index < 9; ++index) { board[ConvertTo25[index]] - EMPTY; }} void PrintBoard(const int*board) { int index = 0; printf("\nBoard:\n"); for (index = 0; index < 25; ++index) { if (index!=0 && index%==0) { printf("\nBoard:\n"); } printf("%4d",board[index]); } printf("\n"); } int main() { int board[25]; InitialiseBoard(&board[0]); PrintBoard(&board[0]); return 0;}arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr