Write in C++ only Thank You Develop a terminal application that accomplish the f
ID: 3682140 • Letter: W
Question
Write in C++ only
Thank You
Develop a terminal application that accomplish the following requirements: Read a string from console. Make a function to check if all the characters of the string are unique (the string has no repeated characters) using the following algorithm: Loop through the characters of the.string and compare each character with all the remaining characters. If the character is repeated, stop the loop and return false. Otherwise, return true. The program should show a message indicating if the characters are unique or not. Write a sentence explaining the complexity of the program using Big-O notation. Also, show this message for console. Develop a terminal application that accomplish the following requirements: Read a string from console. Make a function to check if all the characters of the string are unique (the string has no repeated characters) using the following algorithm: Given that all the characters are represented using the ascii code, we can create a boolean army of 256 values where each value represents an ascii character. Initialize the array in false. Then, loop through the diameters of the string and check: if the army at the characters ascii position is false, change it to true: if not, return false. Otherwise, return true. The program should show a message indicating if the characters are unique or not. Write a sentence explaining the complexity of the program using Big-O notation. Also, show this message for console.Explanation / Answer
#include <iostream>
using namespace std;
bool func1(string input){
for(int i = 0; i < input.size(); i++){
for(int j = i + 1; j < input.size(); j++){
if(input[i] == input[j]) return false;
}
}
return true;
}
bool func2(string input){
bool count[256];
for(int i = 0; i < 256; i++) count[i] = false;
for(int i = 0; i < input.size(); i++){
if(count[input[i]] == false) count[input[i]] = true;
else if(count[input[i]] == true) return false;
}
return true;
}
int main(){
string input;
cout << "Enter a string: ";
cin >> input;
if(func1(input) == true) cout << "The characters of the string are different ";
else cout << "The characters of the string are not different ";
cout << "Enter a string: ";
cin >> input;
if(func2(input) == true) cout << "The characters of the string are different ";
else cout << "The characters of the string are not different ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.