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;
}
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 :)
This is the code I get from the internet about how to make a jumbled string....
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...
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);...
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];...
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)...
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 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...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...
C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) { // Add your code here. string line; getline(inFile, line); int sp = 0; for (int i = 0; i < line.size(); i++) { if (line[i] == ' ') sp++; } sp++; return sp; } int measureLines(ifstream& inFile) { // Add your code here. string line; int n = 0; while (!inFile.eof()) { getline(inFile,...