Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12.2, Problem 12.2CP
Program Plan Intro
Character by character text processing:
- Strings can be accessed or manipulated by using an individual text that is present.
- Different
programming language access the string individually in a different way, some prefer the string gets accessed through subscript notation. - String is considered as list of characters.
Accessing string using subscript notation:
- The string that are accessed using the subscript notation uses subscript “0” to hold the first character and similarly till the last character.
- The last character of the string will be “\0”.
- The first value the index value will be “0” and to find the last character use “length(variable)-1”
Example:
//declare and define a string
Declare String txt = "Hai"
Explanation:
In the above declaration, the given string gets processed in the following way:
txt[0] will hold “H”.
txt[1] will hold “a”.
txt[2] will hold “i”.
Changing the occurrence of the string value that is declared:
- Every value in the string gets accessed individually using the index or subscript value.
- In order to change the character located at a particular position, the index value can be used and it is made as shown below:
Example:
//set the value located at the position 0 as defined
Set txt[0]= “T”
Explanation:
The above line mentioned is used to replace or overwrite the content that is present at the first position.
The word “H” will be replaced with the word “T” for the string “txt” that is declared.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ CODE
small code, allow user to enter string, determind if the prodivied string is a palindrome. inform the user of the result
pls help
#include <iostream>#include <string>
using namespace std;
int GetMonthAsInt(string month) { int monthInt = 0; if (month == "January") monthInt = 1; else if (month == "February") monthInt = 2; else if (month == "March") monthInt = 3; else if (month == "April") monthInt = 4; else if (month == "May") monthInt = 5; else if (month == "June") monthInt = 6; else if (month == "July") monthInt = 7; else if (month == "August") monthInt = 8; else if (month == "September") monthInt = 9; else if (month == "October") monthInt = 10; else if (month == "November") monthInt = 11; else if (month == "December") monthInt = 12; return monthInt;}
int main () { // TODO: Read dates from input, parse the dates to find the ones // in the correct format, and output in m-d-yyyy format
}
Replace any alphabetic character with '_' in 2-character string passCode. Ex: If passCode is "9a", output is:
9_
Hint: Use two if statements to check each of the two characters in the string, using isalpha().
#include <iostream>#include <string>#include <cctype>using namespace std;
int main() {string passCode;
cin >> passCode;
/* Your solution goes here */
cout << passCode << endl;return 0;}
Please help me with the character operations problem in C++.
Chapter 12 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Ch. 12.2 - Prob. 12.1CPCh. 12.2 - Prob. 12.2CPCh. 12.2 - Design an algorithm that determines whether the...Ch. 12.2 - Design an algorithm that determines whether the...Ch. 12.2 - Prob. 12.5CPCh. 12.2 - Prob. 12.6CPCh. 12 - Prob. 1MCCh. 12 - Prob. 2MCCh. 12 - If the str variable contains the string "berry",...Ch. 12 - If the str variable contains the string "Redmond",...
Ch. 12 - Prob. 5MCCh. 12 - Prob. 1TFCh. 12 - Prob. 2TFCh. 12 - If the String variable str contains the string...Ch. 12 - The insert library module automatically expands...Ch. 12 - Prob. 5TFCh. 12 - Prob. 6TFCh. 12 - Prob. 7TFCh. 12 - Prob. 1SACh. 12 - If the following pseudocode were an actual...Ch. 12 - Prob. 3SACh. 12 - Prob. 4SACh. 12 - Prob. 5SACh. 12 - Design an algorithm that counts the number of...Ch. 12 - Prob. 2AWCh. 12 - Design an algorithm that counts the number of...Ch. 12 - Design an algorithm that deletes the first and...Ch. 12 - Design an algorithm that converts each occurrence...Ch. 12 - Design an algorithm that replaces each occurrence...Ch. 12 - Assume the following declaration exists in a...Ch. 12 - Prob. 1DECh. 12 - Prob. 2DECh. 12 - Prob. 3DECh. 12 - Prob. 1PECh. 12 - Sentence Capitalizer Design a program that prompts...Ch. 12 - Prob. 3PECh. 12 - Sum of Digits in a String Design a program that...Ch. 12 - Prob. 5PECh. 12 - Alphabetic Telephone Number Translator Many...Ch. 12 - Word Separator Design a program that accepts as...Ch. 12 - Pig Latin Design a program that reads a sentence...Ch. 12 - Prob. 9PECh. 12 - File Encryption File encryption is the science of...Ch. 12 - File Decryption Filter Design a program that...Ch. 12 - Password Weakness Detector Design a program that...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Urgent solve using C++ Notes: The maximum size of any c-string in this lab is 100 characters and it should be dynamically allocated in the constructor and de-allocated in the destructor. For Visual Studio you need to put the following line as first top line in your source code file: #define _CRT_SECURE_NO_WARNINGS Question 1: The class Person contains the following properties and functions: Name (c-string ), private Age (int), private Address (c-string), private Constructors ( default and non-default) Getters and Setters Destructor: to free the memory and print the message “Object with name [PERSON_NAME] is dead” where PERSON_NAME is the person name for the object being disposed. Print function to print the details of the employee. Test your class with the following main: int main() { Person per1; Person per2("Ahmad", "AUS Campus", 21); cout << "Person per1 :\n"; per1.print(); cout << "\nPerson per2 :\n"; per2.print(); cout<<"\nTesting the setters…arrow_forward. COMPLETE THE CODES.arrow_forwardQ1 part d need code in c++ in visual studio the quotient after q is divided by divisor and assign the result to q. Write this statement in two different ways.arrow_forward
- // ChangeCase.cpp - This program converts characters to lowercase and uppercase.// Input: Interactive// Output: Uppercase and lowercase versions of the user-entered string#include <iostream>#include <string>using namespace std;int main() { const int LEN = 9; char sample1[LEN]; char sample2[LEN]; char result1; char result2; int i; cout << "Enter 9 lowercase characters: "; for(i = 0; i < LEN; i++) { cin >> sample1[i]; // Convert sample1[i] to uppercase and assign it to result1 cout << result1 << endl; } cin.ignore(256,'\n'); cout << "Enter 9 uppercase characters: "; for(i = 0; i < LEN; i++) { cin >> sample2[i]; // Convert sample2[i] to lowercase and assign it to result2 cout << result2 << endl; } cin.ignore(256,'\n'); return 0;} // End of main() functionarrow_forwardString with digit. Set hasDigit to true if the 3-character passCode contains a digit. #include <iostream>#include <string>#include <cctype>using namespace std; int main() { bool hasDigit; string passCode; hasDigit = false; cin >> passCode; isdigit('0') == true; if (hasDigit) { cout << "Has a digit." << endl; } else { cout << "Has no digit." << endl; } return 0;}arrow_forward7. Select the value of target so that the following code outputs: 8std::string str = "appalachian trail";std::cout << str.find(target) << std::endl;A. target = "z"B. target = "ai"C. target = "ia"D. None of the above.arrow_forward
- // SuperMarket.cpp - This program creates a report that lists weekly hours worked // by employees of a supermarket. The report lists total hours for // each day of one week. // Input: Interactive // Output: Report. #include <iostream> #include <string> using namespace std; int main() { // Declare variables. const string HEAD1 = "WEEKLY HOURS WORKED"; const string DAY_FOOTER = " Day Total "; // Leading spaces in DAY_FOOTER are intentional. const string SENTINEL = "done"; // Named constant for sentinel value. double hoursWorked = 0; // Current record hours. string dayOfWeek; // Current record day of week. double hoursTotal = 0; // Hours total for a day. string prevDay = ""; // Previous day of week. bool notDone = true; // loop control // Print two blank lines. cout << endl << endl; //…arrow_forward// SuperMarket.cpp - This program creates a report that lists weekly hours worked // by employees of a supermarket. The report lists total hours for // each day of one week. // Input: Interactive // Output: Report. #include <iostream> #include <string> using namespace std; int main() { // Declare variables. const string HEAD1 = "WEEKLY HOURS WORKED"; const string DAY_FOOTER = " Day Total "; // Leading spaces in DAY_FOOTER are intentional. const string SENTINEL = "done"; // Named constant for sentinel value. double hoursWorked = 0; // Current record hours. string dayOfWeek; // Current record day of week. double hoursTotal = 0; // Hours total for a day. string prevDay = ""; // Previous day of week. bool notDone = true; // loop control // Print two blank lines. cout << endl << endl; //…arrow_forward// SuperMarket.cpp - This program creates a report that lists weekly hours worked // by employees of a supermarket. The report lists total hours for // each day of one week. // Input: Interactive// Output: Report. #include <iostream>#include <string>using namespace std;int main() {// Declare variables.const string HEAD1 = "WEEKLY HOURS WORKED";const string DAY_FOOTER = " Day Total ";// Leading spaces in DAY_FOOTER are intentional.const string SENTINEL = "done"; // Named constant for sentinel value. double hoursWorked = 0; // Current record hours.string dayOfWeek; // Current record day of week.double hoursTotal = 0; // Hours total for a day.string prevDay = ""; // Previous day of week.bool notDone = true; // loop control// Print two blank lines.cout << endl << endl; // Print heading.cout << "\t\t\t\t\t" << HEAD1 << endl;// Print two blank lines.cout << endl << endl; // Read first record cout << "Enter day of week or done to…arrow_forward
- #include #include #include #include using namespace std; int main (){ const double PI = 3.14159265359; return 0; }arrow_forward// LetterE.cpp - This program prints the letter E with 3 asterisks // across and 5 asterisks down. // Input: None // Output: Prints the outline of the letter E. #include <iostream> #include <string> using namespace std; int main() { const int NUM_ACROSS = 3; // Number of asterisks to print across const int NUM_DOWN = 5; // Number of asterisks to print down int row; // Loop control for row number int column; // Loop control for column number // This is the work done in the detailLoop() function // Write a loop to control the number of rows. // Write a loop to control the number of columns // Decide when to print an asterisk in every column. cout << "*"; // Decide when to print asterisk in column 1. cout << "*"; // Decide when to print a space instead of an asterisk. cout << " "; // Figure out where to place this statement that prints a newline.…arrow_forward// LetterE.cpp - This program prints the letter E with 3 asterisks // across and 5 asterisks down. // Input: None // Output: Prints the outline of the letter E. #include <iostream> #include <string> using namespace std; int main() { const int NUM_ACROSS = 3; // Number of asterisks to print across const int NUM_DOWN = 5; // Number of asterisks to print down int row; // Loop control for row number int column; // Loop control for column number // This is the work done in the detailLoop() function // Write a loop to control the number of rows. // Write a loop to control the number of columns // Decide when to print an asterisk in every column. cout << "*"; // Decide when to print asterisk in column 1. cout << "*"; // Decide when to print a space instead of an asterisk. cout << " "; // Figure out where to place this statement that prints a newline.…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Expressions in C++ | C++ tutorial for beginners; Author: Tutorial Mart;https://www.youtube.com/watch?v=XHbsZGpmRc8;License: Standard YouTube License, CC-BY
expression in python # python expressions; Author: Abhishek Tripathi;https://www.youtube.com/watch?v=Cc-kJGRjH6k;License: Standard Youtube License