Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 8.1, Problem 1STE
Explanation of Solution
(i).
Given statement:
//Initialization of char array
char stringVar[10]="Hello";
Explanation:
In the above given statement the string “Hello” is stored in an array as a series of characters.
- First, the character “H” is stored in “stringVar[0]”.
- The character “e” is stored in “stringVar[1]”.
- The character “l” is stored in “stringVar[2]”.
- The character “l” is stored in “stringVar[3]”.
- The character “o” is stored in “stringVar[4]”.
- Finally, the null character “\0” is stored in “stringVar[5]”. So, it print the result “Hello” because the size of array is “stringVar[10]”.
(ii)...
Explanation of Solution
(iii).
Given statement:
// Initialization of char array
char stringVar[10]={'H','e','l','l','o'};
Explanation:
In the above given statement the characters “{'H','e','l','l','o'}”are stored in an array as a series of characters.
- First, the character “H” is stored in “stringVar[0]”...
Explanation of Solution
(iv).
Given statement:
// Initialization of char array
char stringVar[6]="Hello";
Explanation:
In the above given statement the string “Hello” is stored in an array as a series of characters.
- First, the character “H” is stored in “stringVar[0]”.
- The character “e” is stored in “stringVar[1]”.
- The character “l” is stored in “stringVar[2]”.
- The character “l” is stored in “stringVar[3]”.
- The character “o” is stored in “stringVar[4]”.
- Finally, the null character “\0” is stored in “stringVar[5]”. So, it print the result “Hello” because the size of array is “stringVar[6]”.
(v)...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Which method right-aligns a string? a. PadLeft b. PadRight c. LeftAlign d. RightAlign
The encryption and decryption for the Substitution is not working please fix that.
#include <iostream>#include <cstring>
using namespace std;
class Cipher{public:virtual string encode() = 0;virtual string decode() = 0;};
class SubstitutionCipher : Cipher{// int key;string key;string input;
// static string _encode(string input, int key);string _getValidKey();static bool isKeyValid(string key);
public://constructorSubstitutionCipher(string msg, string k){this->input = msg;if (isKeyValid(k)){this->key = k;}else{this->key = _getValidKey();}}
//the function for encryption/decryption (CaesarCipher algorithm)string encode();string decode();};
class CaesarCipher : Cipher{int key;string input;
static string _encode(string input, int key);
public://constructorCaesarCipher(string msg, int k) : input(msg), key(k) {}
//the function for encryption/decryption (CaesarCipher algorithm)string encode();string decode();};…
count the most frequent letter in string permutation
example :
if x = icyz and j = ixpc, then there are 8 different passwords that you can choose: icyz,icyc, icpz, icpc, ixyz, ixyc, ixpz, ixpc.
icpc has the most frequent letter so the output is 2
please help with c++ code (studio.h, string.h,math.h only)
Chapter 8 Solutions
Problem Solving with C++ (9th Edition)
Ch. 8.1 - Prob. 1STECh. 8.1 - What C string will be stored in singingString...Ch. 8.1 - What (if anything) is wrong with the following...Ch. 8.1 - Suppose the function strlen (which returns the...Ch. 8.1 - Prob. 5STECh. 8.1 - How many characters are in each of the following...Ch. 8.1 - Prob. 7STECh. 8.1 - Given the following declaration and initialization...Ch. 8.1 - Given the declaration of a C-string variable,...Ch. 8.1 - Write code using a library function to copy the...
Ch. 8.1 - What string will be output when this code is run?...Ch. 8.1 - Prob. 12STECh. 8.1 - Consider the following code (and assume it is...Ch. 8.1 - Consider the following code (and assume it is...Ch. 8.2 - Consider the following code (and assume that it is...Ch. 8.2 - Prob. 16STECh. 8.2 - Consider the following code: string s1, s2...Ch. 8.2 - What is the output produced by the following code?...Ch. 8.3 - Is the following program legal? If so, what is the...Ch. 8.3 - What is the difference between the size and the...Ch. 8 - Create a C-string variable that contains a name,...Ch. 8 - Prob. 2PCh. 8 - Write a program that inputs a first and last name,...Ch. 8 - Write a function named firstLast2 that takes as...Ch. 8 - Write a function named swapFrontBack that takes as...Ch. 8 - Prob. 6PCh. 8 - Write a program that inputs two string variables,...Ch. 8 - Solution to Programming Project 8.1 Write a...Ch. 8 - Write a program that will read in a line of text...Ch. 8 - Give the function definition for the function with...Ch. 8 - Write a program that reads a persons name in the...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that can be used to train the user...Ch. 8 - Write a sorting function that is similar to...Ch. 8 - Redo Programming Project 6 from Chapter 7, but...Ch. 8 - Redo Programming Project 5 from Chapter 7, but...Ch. 8 - Prob. 11PPCh. 8 - Write a program that inputs a time from the...Ch. 8 - Solution to Programming Project 8.14 Given the...Ch. 8 - Write a function that determines if two strings...
Knowledge Booster
Similar questions
- C++ Help. "qwerty" is a string commonly found in weak passwords. Remove all occurrences of "qwerty" from secretStr. Then, assign lengthStr with the length of secretStr. Ex: If the input is qwertyvk*M7$gKXhJ%P9qwerty, then the output is: Remaining string: vk*M7$gKXhJ%P9 Length: 14 Note: string.find(item) returns the index of the first occurrence of item in string. If no occurrence is found, then the function returns string::npos. string.replace(indx, num, subStr) replaces characters at indices indx to indx+num-1 with a copy of subStr. Code provided to complete: #include <iostream>#include <string>using namespace std; int main() { string secretStr; int index; int lengthStr; cin >> secretStr; index = 0; lengthStr = 0; /* Your code goes here */ cout << "Remaining string: " << secretStr << endl; cout << "Length: " << lengthStr << endl; return 0;}arrow_forwardcount the frequent letter of the combined of two string example : if x = icyz and j = ixpc, then there are 8 different passwords that you can choose: icyz,icyc, icpz, icpc, ixyz, ixyc, ixpz, ixpc. icpc has the most frequent letter so the output is 2 please help with c++ code (studio.h, string.h,math.h only)arrow_forwardModify songVerse to play "The Name Game" (see OxfordDictionaries.com), by replacing "(Name)" with userName but without the first letter.Ex: If userName = "Katie" and songVerse = "Banana-fana fo-f(Name)!", the program prints:Banana-fana fo-fatie! Ex: If userName = "Katie" and songVerse = "Fee fi mo-m(Name)", the program prints:Fee fi mo-matie Note: You may assume songVerse will always contain the substring "(Name)" #include <iostream>#include <string>using namespace std; int main() {string userName;string songVerse; getline(cin, userName);userName = userName.substr(1, userName.size() - 1); // Remove first character getline(cin, songVerse); // Modify songVerse to replace (Name) with userName without first character /* Your solution goes here */ cout << songVerse << endl; return 0;} Please help me with this string operations problem using C++.arrow_forward
- Q3 - Which of the following converts a type to a string in C#? A-Toint64 B-ToSbyte C - ToSingle D-ToStringarrow_forwardModify the CategorizeStrings application to divide the entered Strings into those that contain no spaces, one space, or more. After data entry is complete, continuously prompt the user to enter the type of String to display: O for one word Strings, T for two word Strings, and L for longer Strings. If the user does not enter one of the three valid choices, display all of the Strings. Allow the user to enter ZZZ to quit. import java.util.*;public class CategorizeStrings2{// Modify the code belowpublic static void main (String[] args){final int MAX = 20;final int CUTOFF = 10;final String QUIT = "ZZZ";String entry;int shortSub = 0;int longSub = 0;Scanner input = new Scanner(System.in);String[] longStrings = new String[MAX];String[] shortStrings = new String[MAX]; System.out.print("Enter a string or " +QUIT + " to quit >> ");entry = input.nextLine();while(!entry.equals(QUIT) && (shortSub + longSub < MAX)){if(entry.length() <= CUTOFF){shortStrings[shortSub] =…arrow_forwardGiven the following code, match the code with the correct output public static String sub(String str) { return str.substring(str.indexOf(",") + 1, str.indexOf(",", str.indexOf(",") + 1)); } public static String sub2(String str) { return str.substring(str.indexOf("@")); } public static String sub3(String str) { String rtn = ""; String key = "KitHawk"; String key2 = "abcdefgh"; rtn += key2.charAt(key.indexOf(str.charAt(0))); rtn += key2.charAt(key.indexOf(str.charAt(1))); rtn += key2.charAt(key.indexOf(str.charAt(2))); return rtn; } Choices: sub3("Kakwit") sub2("frankie@rhps.com") sub("Brad,Magenta,Columbia") Answers to match with the choices frankie@ Magenta Columbia aeg abc @rhps.com @ Brad ,Magenta Magenta, rhps.com defarrow_forward
- Create and construct an application that receives a string from the user, counts the number of each lowercase vowel (a, e, i, o, and u) that appear in the entire string, and outputs the results. Give each vowel its own counter. Count and publish the amount of characters that aren't vowels as well.arrow_forwardGiven string stringValue on one line, string addStr on a second line, and string partialString on a third line, insert the contents of addStr in stringValue right before the first occurrence of partialString. Ex: If the input is: FuzzyBear Wuzzy Be then the output is: FuzzyWuzzyBear #include <iostream>#include <string>using namespace std; int main() { string stringValue; string addStr; string partialString; getline(cin, stringValue); getline(cin, addStr); getline(cin, partialString); /* Your code goes here */ cout << stringValue << endl; return 0;}arrow_forwardA. Which statement about regular expressions is correct? a. To find all occurrences of a matching substring for a regular expression, you must add thegflag. b. By default, pattern matching using regular expressions locates all matches in the searched string. c. To find all occurrences of a matching substring for a regular expression, you must add theiflag. d. The default behavior of a regular expression is modified by adding flags to the beginning of the expression. B. After the following JavaScript statements execute, the value ofcrayonsis["pink", "blue", "green"]. let crayons = ["pink", "purple"];crayons.shift();crayons.unshift("blue", "green"); Select one: True Falsearrow_forward
- Print a message telling a user to press the letterToQuit key numPresses times to quit. End with newline. Ex: If letterToQuit = 'q' and numPresses = 2, print:Press the q key 2 times to quit. #include <iostream>using namespace std; int main() { char letterToQuit; int numPresses; cin >> letterToQuit; cin >> numPresses; /* Your solution goes here */ return 0;}arrow_forwardEach of the following files in the Chapter.07 folder of your downloadable student files has syntax and/or logical errors. In each case, determine the problem, and fix the program. After you correct the errors, save each file using the same filename preceded with Fixed. For example, DebugSeven1.cs will become FixedDebugSeven1.cs. a. DebugSeven1.cs b. DebugSeven2.cs c. DebugSeven3.cs d. DebugSeven4.csarrow_forwardPART E: ROTATE LEFTGiven a string str, print out a rotated left 2 version where the first 2 chars are moved to the end. Assume thestring length will be at least 2.Methods to use: substring(), length(), concat()Testing cases: Hello => lloHe java => vaja Hi => Hi code => deco cat => tca 12345 => 34512 Chocolate => ocolateCh bricks => icksbarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning