Starting Out with Programming Logic and Design (4th Edition)
4th Edition
ISBN: 9780133985078
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12, Problem 4SA
Program Plan Intro
Character testing library functions:
- Library functions other than the string library functions are provided by
programming language, which are intended to work with single characters. - The support library functions are used for testing the value of the character.
- The function will return the Boolean result on testing; the result will be in “True” or “False” format.
isUpper(character):
- This function is used to validate whether the character given is upper case letter.
- The function will return “True” if the character is in upper case.
- The function will return “False” if the character is in lower case.
isLower(character):
- This function is used to validate whether the character given is lower case letter.
- The function will return “True” if the character is in lower case.
- The function will return “False” if the character is in upper case.
Example:
The below
//determine if the first character is in upper case
If isUpperCase (str[0]) Then
//replace the values present at the first position
Set str [0] = "0"
//end if
End If
Explanation:
- If condition validates the first position of the “str” is in upper case or not.
- If the condition becomes true, the character at positon “0” gets replaced with the character “0”.
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 first value the index value will be “0” and to find the last character use “length(variable)-1”.
- When a string is tried to access using an invalid subscript, it will throw an error.
Analysis of the given statement:
//declare and define a string
Declare string str= “Might”
//set the value located at the subscript 5 as defined
Set str[5] = “y”
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The Print Statement takes a list of elements to print, separated by commas. IF the element is a string, THEN _____.
a. None of the above
b. Print the value associated with the variable
c. Print it as is
d. Print the result of performing the calculation
#include<iostream>#include<string.h>using namespace std;
struct student{ int number; string name; int age; string city;}s[10];
struct module{ int number; string name; string code; int credit;}m[10];
struct assessment{ int number; int marks1; int marks2;}a[10];
int index1 =0, index2=0, index3=0;
void StudentRegistration(){ if(index1==10) { cout<<"No more data can be added"<<endl; return; } string temp; cout<<"Enter personal data"<<endl; cout<<"Enter Student Number"<<endl; cin>>s[index1].number; cout<<"Enter Student Name"<<endl; getline(cin, temp); getline(cin,s[index1].name); cout<<"Enter Age"<<endl; cin>>s[index1].age; cout<<"Enter city"<<endl; getline(cin,temp); getline(cin,s[index1].city); index1++;}
void ModuleEnrolment(int id){ if(index2==10) { cout<<"No more data can be…
What will the following program segments display?A) for (int count = 0; count < 6; count++)cout << (count + count);B) for (int value = −5; value < 5; value++)cout << value;C) int x;for (x = 5; x <= 14; x += 3)cout << x << endl;cout << x << endl;
Chapter 12 Solutions
Starting Out with Programming Logic and Design (4th Edition)
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...
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
- A structure that allows repeated execution of a block of statements is a(n) _____________. sequence selection array looparrow_forwardIn C programming language Question (Strings) Write a function find_Substring() that finds a substring into a string. Pass array s1 and s2 to this function and prints if the substring is present or not. Expected Output 1: Enter string This is a javascript Enter substring script The substring is present Expected Output 2: Enter string This is a javascript Enter substring Jscript The substring is not presentarrow_forwardGiven string userString on one line, character newChar on a second line, and integer strIndex on a third line, change the character at index strIndex of userString to newChar. Ex: If the input is: garlic Z 0 then the output is: Zarlic Note: Assume the length of string userString is greater than strIndex. #include <iostream> #include <string> using namespace std; int main() { string userString; char newChar; int strIndex; getline(cin, userString); cin >> newChar; cin >> strIndex; /* Your code goes here */ cout << userString << endl; return 0; }arrow_forward
- Morse Code Python Part 1: Variable setup and prompt for input• To create the Morse representations, use periods “.” for dots and hyphens “-“ for dashes. Forexample, the Morse representation for the letter “C” is “-.-.”. A table of the alphabet can befound here.• Create a dictionary where the keys are a single letter (you can choose if it’s upper case or lowercase) and the value is a string with the Morse representation of the letter.• Create a loop to prompt the user for input – if they press the enter key, quit the loop.Otherwise, continue to prompt the user for input. Part 2: Convert to visual Morse code• Create an empty string to eventually hold the user’s output in Morse code. • Analyze each character of the user’s input. Since Morse code is capitalization independent thealgorithm should work the same for uppercase letters and lowercase letter. I recommendperfecting your code for 1 of the two cases, then fixing it for both cases.• If the user types anything except a letter or a…arrow_forwardPlease help me with this using java. Create a selection sort java code Please also comment the codearrow_forwardPlease help me how can I write the code here #include <iostream>#include <string> // Function to repeat a string by a given integerstd::string multiply(const std::string& str, int num) { std::string result; for (int i = 0; i < num; ++i) { result += str; } return result;} // Function to multiply two integersint multiply(int num1, int num2) { return num1 * num2;} // Function to multiply a double and an integerdouble multiply(double num1, int num2) { return num1 * num2;} // Function template to handle multiple data typestemplate <typename T>T multiply_type(T num1, int num2) { return num1 * num2;} int main() { int choice; std::cout << "Choose a test case (1-5): "; std::cin >> choice; switch (choice) { case 1: { int num1, num2; std::cout << "Enter two integers: "; std::cin >> num1 >> num2; int result = multiply(num1, num2); std::cout…arrow_forward
- #include<iostream> using namespace std; string name; int number; int age; string city; string module1_name; string module1_code; int module1_credit; string module2_name; string module2_code; int module2_credit; int module1_marks; int module2_marks; void student_registration() { cout<<"\nEnter Student ID: "; cin>>number; cout<<"\nEnter Student's name : "; cin>>name; cout<<"\nEnter age : "; cin>>age; cout<<"\nEnter city : "; cin>>city; } void module_enrolment() { cout<<"\nEnter Module1 name : "; cin>>module1_name; cout<<"\nEnter Module1 code : "; cin>>module1_code; cout<<"\nEnter Module1 credits : "; cin>>module1_credit; cout<<"\nEnter Module2 name : "; cin>>module2_name; cout<<"\nEnter Module2 code : "; cin>>module2_code; cout<<"\nEnter Module2…arrow_forwardchar lastChar(const char *str){ char last; //loop over the string and go uptill end of the string \0 while(*str !='\0'){ str++; // increment pointer last = *str; //store the current character to the last variable } return last; //last character is returned}arrow_forwardNote: it`s python coding Implement the following: Given: names = ['ann', 'bill', 'calvin', 'david']ids = [12, 34, 56, 78] 1) Create a dictionary, stuInfo by using the two given lists above.2) Use a loop to print all keys and values in the dictionary stuInfo.3) Print the dictionary, stuInfo. Make sure to precisely match the output format below.Write your code in the ANSWER area provided below (must include comments if using code is not covered in the course). Example Output12 ANN34 BILL 56 CALVIN78 DAVID{'ann': 12, 'bill': 34, 'calvin': 56, 'david': 78}arrow_forward
- This application accepts an arbitrary number of user inputs. Every time this application receives a string, it should add the string to a growing string.Newly added strings should be added to the growing string at the index equal to the newly added string's length.arrow_forwardThe code is here for C language. But the words did not get remove as wanted. The output picture shows the output. Please help. #include <stdio.h>#include <stdlib.h>#include <string.h> int main (){ char string[1000], word[1000], array[100][150]; //showing the maximum size for string, word and array int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, count = 0; printf ("Enter the string:\n"); //user input a sentence gets(string); printf ("Enter the word to be removed:\n"); //inputs the words to be removed gets (word); // (Removing process condition) for (i = 0; string[i] != '\0'; i++) { if (string[i] == ' ') { array[k][j] = '\0'; k ++; j = 0; } else { array[k][j] = string[i]; // Change 1 j ++; } } array[k][j] = '\0'; j = 0; for (i = 0; i < k + 1; i++) { if (strcmp(array[i], word) == 0)…arrow_forwardCreate a flowchart for the following code. namesList=['Juan','Rae','Ivanna','Lilly','Robert']; #list to store names wagesHoursDict={7.50:35, 11.00:41, 18.25:26, 9.25:35, 11.10:45}; #dictionary to store wages and hours grossPay=0; #variable to store gross pay wagesList=list(wagesHoursDict.keys()); #convert all the keys of dictionary to listhoursList=list(wagesHoursDict.values()); #convert all the values of dictionary to list print("Name\tWages\tHours\tGross Pay"); #print header for i in range(0,5): if(hoursList[i]>40): #if hours more than 40 #calculate basic for 40 hours and 1.5 times basic for remaining hours grossPay=(wagesList[i]*40)+(1.5*wagesList[i]*(hoursList[i]-40)); else: grossPay=wagesList[i]*hoursList[i]; #calculate hours*wage print(namesList[i],"\t",wagesList[i],"\t",hoursList[i],"\t",grossPay); #printing all the valuesarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,