Question

In: Computer Science

Hi i need a c++ program that can convert charactor into numbers pseodocode user input their...

Hi i need a c++ program that can convert charactor into numbers

pseodocode

user input their name

for example john

every single charactor should have a value so it return correct result

eg:

j=2, o=1, h=7,n=2

and display these numbers

if you may need any question to ask me, i will be very happy to answer them.

Thanks!

example project close but not accurate

#include
#include
#include
#include
#include
#include
#include
#include
#define INPUT_SIZE 8

using namespace std;

// Function to reverse a string
void reverseStr(string& str)
{
   int n = str.length();

   // Swap character starting from two
   // corners
   for (int i = 0; i < n / 2; i++)
       swap(str[i], str[n - i - 1]);
}
int main() {
   const std::string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   std::string text;
   std::cin >> text;

   // convert all lower case characters to upper case
   for (char& c : text) c = std::toupper(c);

   // sum up the values of alpha characters ('A' == 1, 'B' == 2 etc.)
   int sum = 0;
   for (char& c : text) // for each character c in text
   {
       // locate the character in alpha
       // http://www.cplusplus.com/reference/string/string/find/
       const auto pos = alpha.find(c);

       if (pos != std::string::npos) // if found (if the character is an alpha character)
                                   // note: non-alpha characters are ignored
       {
           const int value = pos + 1; // +1 because position of 'A' is 0, value of 'A' is 1
           sum += value;
           cout << sum;
       }
   }

more info is here:

https://www.chegg.com/homework-help/questions-and-answers/hi-need-c-program-convert-charactor-numbers-pseodocode-user-input-name-example-john-every--q40281532?trackid=qn_1uBwb

I JUST WANT TO REPLACE THE FINAL VALUE GIVEN FOR EACH CHAR WITH ANOTHER NUMBER FOR EXAMPLE IF THEY ENTER JOHN

IT SHOULD PRINT VALUE OF JOHN WHICH I SPECIFY FOR THAT NOT THE RANDOM VALUE OR POSITION VALUE AS RESULT OF THIS PROGRAM THANK YOU IN ADVANCE

Solutions

Expert Solution

Please do let me know if anything is required.

Below code to print the number representation of each character in the string and sum of all characters represented as numbers in the string.

Code :

#include<iostream>
#include<string>
#include<exception>
#include <cstdlib>
#include<stdio.h>
#include<map>
#include <cctype>
#define INPUT_SIZE 8

using namespace std;

int main() {
const std::string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

std::string text;

//Taking the string from the user
cout<<"Enter the string : ";
std::cin >> text;

// convert all lower case characters to upper case
for (char& c : text) c = std::toupper(c);

// sum up the values of alpha characters ('A' == 1, 'B' == 2 etc.)
int sum = 0;
cout<<"\nThe number representation of each character in the string is\n****** ";
for (char& c : text) // for each character c in text
{
// locate the character in alpha
// http://www.cplusplus.com/reference/string/string/find/
const auto pos = alpha.find(c);

if (pos != std::string::npos) // if found (if the character is an alpha character)
// note: non-alpha characters are ignored
{
const int value = pos + 1; // +1 because position of 'A' is 0, value of 'A' is 1

sum += value; //summing the number of values of each chanracter in to the variable sum

//printing the number value of each character in the string
cout << value;
}
}

//printing the total of all characters represented as numbers in the string
cout<<" ******\n\nThe Total sum of all characters represented as numbers in the string is \n****** "<<sum<<" ******\n";
}

Test 1 :

Test 2 :


Related Solutions

Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
I have to create a program in C++ where a user can enter as many numbers...
I have to create a program in C++ where a user can enter as many numbers as they want (they predetermine the number of values to be inputted) and then the program can echo that input back to the user and then determine if the numbers were even, odd, or a zero and it outputs how many of each were found. This is to be down with four void functions and no arrays. The program initializes the variables zero, odds,...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers...
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers for height and width and uses a nested for loop to make a rectangle out of asterixes. The creation of the rectangle (i.e. the nested for loop) should occur in a void function that takes in 2 parameters, one for height and one for width. Make sure your couts match the sample output (copy and paste from those couts so you don't make a...
Hello, I stuck doing c++ program The program will be recieved from the user as input...
Hello, I stuck doing c++ program The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to...
hi i need to do a C++ program. You are going to practice the use of...
hi i need to do a C++ program. You are going to practice the use of array by implementing the interface of Shuttle Puzzle. Here is an example of how you play the Shuttle Puzzle. Say that you start with a board with 7 holes and there are 3 black and 3 white marbles on the board in this configuration: W W W . B B B The dot (.) represents the empty hole withouth any marble. The objective of...
I need to ask a user what numbers they want to enter. They can enter as...
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't...
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic:...
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic: Ask for a number, add that number to the front of the list, print the list. Repeat until they enter -1 for the number. . Sample Input: 10, 15, 5, 2, 4, -1 Output: 4, 2, 5, 15, 10. Next sort all the numbers using selection sort and display them. Next give the user option to search for a specific number in the list....
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic:...
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic: Ask for a number, add that number to the front of the list, print the list. Repeat until they enter -1 for the number. . Sample Input: 10, 15, 5, 2, 4, -1 Output: 4, 2, 5, 15, 10. Next sort all the numbers using selection sort and display them. Next give the user option to search for a specific number in the list....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT