Question

This is the code I get from the internet about how to make a jumbled string....

This is the code I get from the internet about how to make a jumbled string. Some of them are confused. Can I get pseudocode for that? (C++ please)

string Jumblestring(string input)
{
   int count = input.length();
   int i, j, mid;
   string temp = "";
   for (i = 0; i < count; i++)
       temp.append(" ");
   if (count % 2 == 1)
       mid = count / 2;
   else
       mid = count / 2 - 1;
   for (i = 0; i <= mid; i++)
       temp[i] = input.at(mid - i);
   for (i = 2, j = 0; i < count; i++, j++)
       temp[i] = input.at(count - 1 - j);
   return temp;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

declare function jumbleString with parameter input string

set count to store the length of input string

declare i, j, mid

set temp string to ""(empty)

for i in range 0 to count

append " "(space) in the temp

end for

if count is odd

mid = count/2

else

mid = count/2-1

for i in range 0 to mid

set temp[i] to input[mid-i]

end for

for i in range 2 to count and j in range 0 to count

set temp[i] to input[count-1-j]

end for

return temp string

end jumbleString function

/*********************jumbled.cpp************************/

#include<iostream>
#include<cstring>
#include<stdlib.h>
using namespace std;

string jumbleString(string& str)
{
int x = str.length();
for(int y = x; y > 0; y--)
{
int pos = rand()%x;
char tmp = str[y-1];
str[y-1] = str[pos];
str[pos] = tmp;
}
return str;
}
int main(){
  
   string str;
   cout<<"Please enter a string to get jumbled string ";
   cin>>str;
   cout<<"\nThe jumbled string is: "<<jumbleString(str);
}

#include<iostream>
#include<cstring>
#include<stdlib.h>
using namespace std;

string jumbleString(string& str)
{
int x = str.length();
for(int y = x; y > 0; y--)
{
int pos = rand()%x;
char tmp = str[y-1];
str[y-1] = str[pos];
str[pos] = tmp;
}
return str;
}
int main(){
  
   string str;
   cout<<"Please enter a string to get jumbled string ";
   cin>>str;
   cout<<"\nThe jumbled string is: "<<jumbleString(str);
}

/*************output*****************/

Please enter a string to get jumbled string Apple

The jumbled string is: lAppe
--------------------------------

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
This is the code I get from the internet about how to make a jumbled string....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {...

    Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {         int[] array = {7, 1, 3, 2, 42, 76, 9};         insertionSort(array);     }     public static int[] insertionSort(int[] input) {         int temp;         for (int i = 1; i < input.length; i++) {             for (int j = i; j > 0; j--) {                 if (input[j] < input[j - 1]) {                     temp = input[j];                     input[j] = input[j - 1];                     input[j - 1] = temp;                 }             }             display(input, i);...

  • use the same code. but the code needs some modifications. so use this same code and...

    use the same code. but the code needs some modifications. so use this same code and modify it and provide a output Java Program to Implement Merge Sort import java.util.Scanner Class MergeSort public class MergeSort Merge Sort function / public static yoid sortfintfl a, int low, int high) int N-high-low; if (N1) return; int mid- low +N/2; Il recursively sort sort(a, low, mid); sort(a, mid, high); I/ merge two sorted subarrays int] temp new int[N]; int i- low, j-mid; for...

  • I need to now how to input the following code into the complier for C++ code....

    I need to now how to input the following code into the complier for C++ code. It is for chapter 8 question 7a in the PLD book // Start //     Declarations //         num MAXADS = 100 //         num adcatcode[MAXADS] //         num adwords[MAXADS] //         num curCode //         num numads //         num i //         num j //         num k //         num subtotal //         num temp //     output "Please enter the number of ads: " //     input numads //     if ((numads > 0)...

  • Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular a...

    Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...

  • Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void...

    Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void messageAndKey(){ string msg; cout << "Enter message: "; getline(cin, msg); cin.ignore(); //message to uppercase for(int i = 0; i < msg.length(); i++){ msg[i] = toupper(msg[i]); } string key; cout << "Enter key: "; getline(cin, key); cin.ignore(); //key to uppercase for(int i = 0; i < key.length(); i++){ key[i] = toupper(key[i]); } //mapping key to message string keyMap = ""; for (int i = 0,j...

  • Please fix my code so I can get this output: Enter the first 12-digit of an...

    Please fix my code so I can get this output: Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number is 9780132130806 This was my output: import java.util.Scanner; public class Isbn { private static int getChecksum(String s) { // Calculate checksum int sum = 0; for (int i = 0; i < s.length(); i++) if (i % 2 == 0) sum += (s.charAt(i) - '0') * 3; else sum += s.charAt(i) - '0'; return 10...

  • I need help with my code when I run my code running the wrong thing like...

    I need help with my code when I run my code running the wrong thing like this After downSize() words.length=60003 wordCount=60003 vowelCount=206728 this is my code here import java.io.*; import java.util.*; public class Project02 {    static final int INITIAL_CAPACITY = 10;    public static void main (String[] args) throws Exception    {        // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE        if (args.length < 1 )       ...

  • How would I be able to get a Merge Sort to run in this code? MY...

    How would I be able to get a Merge Sort to run in this code? MY CODE: #include <iostream> #include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h> using namespace std; class mergersorter { private:    float array[1000] ;    int n = 1000;    int i=0; public:    void fillArray()    {        for(i=1;i<=n;i++)        {            array[i-1]= ( rand() % ( 1000) )+1;        }    }    void arrayout ()    {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT