Hello,
The C++ question is:
-------------------------------------------------------------------------------
Write a program that takes as input 2 strings from the user. Then it determines if one string is a permutation of the other string.
If the program answers "yes" to the previous question, meaning the two strings are permutations of each other, determine if each string has all unique characters.
---------------------------------------------------------------------------------
I have completed the first part but I am unsure on how to also determine if each string is all unique characters
-------------------------------------------------------------------------------
#include <iostream>
#include <algorithm>
using namespace std;
// Checking if two strings are permutation
bool permutationcheck(string in1, string in2)
{
// Length of both of the strings
int n1 = in1.length();
int n2 = in2.length();
if (n1 != n2)
return false;
// Sorting
std::sort(in1.begin(), in1.end());
std::sort(in2.begin(), in2.end());
// comparing now that they are sorted
for (int i = 0; i < n1; i++)
if(in1[i] != in2[i])
return false;
return true;
}
int main()
{
string in1;
string in2;
cout << "Enter two strings: " << endl;
cin >> in1 >> in2;
if(permutationcheck(in1, in2))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
-------------------------------------------------------------------------------------------------
#include <iostream>
#include <algorithm>
using namespace std;
bool unique_chars(string str){
int n = str.length(), i, j;
for(i = 0;i<n;i++){
for(j = 0;j<i;j++){
if(i!=j && str[i] == str[j]){
return false;
}
}
}
return true;
}
// Checking if two strings are permutation
bool permutationcheck(string in1, string in2)
{
// Length of both of the strings
int n1 = in1.length();
int n2 = in2.length();
if (n1 != n2)
return false;
// Sorting
std::sort(in1.begin(), in1.end());
std::sort(in2.begin(), in2.end());
// comparing now that they are sorted
for (int i = 0; i < n1; i++)
if(in1[i] != in2[i])
return false;
return true;
}
int main()
{
string in1;
string in2;
cout << "Enter two strings: " << endl;
cin >> in1 >> in2;
if(permutationcheck(in1, in2)){
cout << "Yes" << endl;
if(unique_chars(in1)){
cout<<"All unique characters"<<endl;
}
else{
cout<<"String does not have all unique characters"<<endl;
}
}
else
cout << "No" << endl;
return 0;
}


Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from...
I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...
I'm trying to write in C++ a way to have the user input an double one at a time and have the program output (on entering 0) the number of times those variables differ by at least 1. For example if I enter 1, 1.7, 0.8, -0.1, -1, 0 ... I should get back 4. (or if I just input 0, the output should just be 0). I'm having trouble understanding how to use a while/for operation to make this...
C++ XOR two strings. I am trying to XOR two strings 00112233445566778899AABBCCDDEEFFAABB060606060606 and 4ca00fd6dbf1fb284ca00fd6dbf1fb284ca00fd6dbf1fb28 my program is giving me: SPTWPVSPT[X q'&t'!"u#'t~u"#rPTTTVVT as a result However, when i go to http://xor.pw/? and input the two hexadecimal strings in I get the result: 4cb12de59fa49d5fc439a56d172c15d7e61b09d0ddf7fd2e what am I doing wrong in my program below? // plaintext value here string pthex = "00112233445566778899AABBCCDDEEFFAABB"; // IV value here string sHex = "4ca00fd6dbf1fb28"; string PaddedPlainText = pthex + "060606060606"; //added the pad //cout<<PaddedPlainText<<endl; // the above...
In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...
Multi Part question for c++ thank you and yes I'm going to rate you up thanks ^^ Part A Question #1 Write a program that takes as input 2 strings from the user. Then it determines if one string is a permutation of the other string. Question #2 If the program answers "yes" to the previous question, meaning the two strings are permutations of each other, determine if each string has all unique characters. Hint: For comparing strings you can...
// Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...
C++ question Input Format You are given two strings, a and b, separated by a new line. Each string will consist of lower case Latin characters ('a'-'z'). Output Format In the first line print two space-separated integers, representing the length of a and b respectively. In the second line print the string produced by concatenating a and b (a+b). In the third line print two strings separated by a space, a' and b'. a' and b' are the same as...
test.txtLab7.pdfHeres the main.cpp:#include "Widget.h"#include <vector>#include <iostream>#include <string>#include <iomanip>#include <fstream>using std::ifstream;using std::cout;using std::cin;using std::endl;using std::vector;using std::string;using std::setprecision;using std::setw;bool getWidget(ifstream& is, Widget& widget){ string name; int count; float unitCost; if (is.eof()) { return false; } is >> count; is >> unitCost; if (is.fail()) { return false; } is.ignore(); if (!getline(is, name)) { return false; } widget.setName(name); widget.setCount(count); widget.setUnitCost(unitCost); return true;}// place the definitions for other functions here// definition for function mainint main(){ // Declare the variables for main here // Prompt the...
Create a program with the main function and one additional function. The additional function asks for input from the user and returns the output back to the main function for display. This is for c++ and here is my code, could you guys please tell me what I am missing from the instructions. Thank you #include <iostream> using namespace std; int sum (int, int); int main() { int n1, n2, total; cout << "Enter two numbers...
Having code issues wth my C++ program. My program checks if two binary trees are similar and if they're not they return false. My program is return true with different binary trees. Could use some help thanks #include <iostream> #include <string> using namespace std; //Struct of Nodes struct BinarySearchTree { int data; BinarySearchTree *left; BinarySearchTree *right; }; // Inserting nodes into BST BinarySearchTree* insert( BinarySearchTree* node, int val) { if (node == NULL) { BinarySearchTree *newNode = new BinarySearchTree(); newNode->data...