C++
10.4 String to number
Write a program that
1.reads in 4 upper case characters
3.Adds all these numbers together
Converts this resulting integer to a string
Prints the string.
Divides the integer result by 4
Converts this back to an Ascii char
prints the char
#include <iostream>
#include <string>
using namespace std;
int main() {
string word;
cout << "Enter 4 uppercase letters: ";
// 1.reads in 4 upper case characters
cin >> word;
// Converts each into its Ascii equivalent integer
int sum = 0;
for (int i = 0; i < word.size(); ++i) {
// 3.Adds all these numbers together
sum += word[i];
}
// Converts this resulting integer to a string
string result = std::to_string(sum);
// Prints the string.
cout << result << endl;
// Divides the integer result by 4
sum /= 4;
// Converts this back to an Ascii char
char ch = (char)sum;
// prints the char
cout << ch << endl;
return 0;
}
C++ 10.4 String to number Write a program that 1.reads in 4 upper case characters Converts...
C++
Lab Quiz #3-B Upper Case Letters Write a main() program that reads a string and calls the function int countUpper(string) which counts and returns the number of upper case letters in the string. The main) prints the result Sample inputs/outputs: nter a string: This is a C++ quIz numBer 4 This is a C++ quIz numBer 4" has 5 upper letters
Question 4 5 Write a function to upper that converts a string from lower case to change it to "HELLO": Remember that you can test if a char is between 'a and z. inclusive, and that capital chars int main0i upper case. For the following function, to upper should accept hello as an are 32 less than lower case chars char sil "hello" printf("s-%s\n", s); to uppers): printf("s-%sin", s); return O: The program output should be: s hello s HELLO...
This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...
Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...
Problem 1: Write a program that reads a positive float number and displays the previous and next integers. Sample Run: Enter a float: 3.5 The previous and next integers are 3 and 4. Problem 2: Write a program that reads two integers and displays their sum, difference, product, and the result of their division. Sample Run: Enter two integers: 8 5 Sum: 8, Difference: 3, Product: 40, Division: 1.6 Problem 3: Write a program that reads a three-digit integer from...
Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....
Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...
Write a C++ program that defines a function that converts a binary number string to an integer. However, if the binary number is greater than or equal to 4,294,967,296, the function must return 0.
Write a C program that reads characters from a text file, and recognizes the identifiers in the text file. It ignores the rest of the characters. An identifier is a sequence of letters, digits, and underscore characters, where the first character is always a letter or an underscore character. Lower and upper case characters can be part of the identifier. The recognized identifier are copied into the output text. b. Change the C program in exercise 2, so that all...
1. Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters. Sample String : 'The quick Brow Fox' Expected Output : No. of Upper case characters : 3 No. of Lower case Characters : 12