Question

In: Computer Science

Do not use c-string, arrays, and read input characters one by one. Also use : s.push_back(ch);....

Do not use c-string, arrays, and read input characters one by one. Also use : s.push_back(ch);. Code a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered .The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Eg: Enter a sequence of characters: abAa1121X+&$%$dc[space] Distinct characters are: abA12X+&$%dc. Use C++

Solutions

Expert Solution

input code:

output:

code:

#include <iostream>
#include<vector>
using namespace std;

int main()
{
/*vector for store characters*/
vector<char> s;
char ch='a';
/*take characters one by one*/
cout<<"Enter a sequence of characters:\n";
cin.get(ch);
while(ch!=' ')
{
/*flag */
int flag=1;
/*check already entered or not*/
for(int i=0;i<s.size();i++)
{
/*if found than make flag=0*/
if(s[i]==ch)
{
flag=0;
break;
}
}
/*if flag=1 than add into vector*/
if(flag==1)
{
s.push_back(ch);
}
/*take characters again*/
cin.get(ch);
}
/*output string*/
string output="";
/*store into string from vector*/
for(int i=0;i<s.size();i++)
{
output+=s[i];
}
/*print a string*/
cout<<"Distinct characters are: "<<output;
return 0;
}


Related Solutions

Given a string of at least 3 characters as input, if the length of the string...
Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint. -------------------------------------------------------------- public class Class1 { public static String midString(String str) {     //Enter code here } }
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You are NOT allowed to use any C++ string data type variable for any purpose. Moreover, you are allowed to add any include directive. You are not allowed to include string, cstdlib or math libraries. Also, you are not allowed to use any built-in functions of c-strings. can someone help with the third, fourth, and fifth functions? I tried many ways but i cannot figure...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You are NOT allowed to use any C++ string data type variable for any purpose. Moreover, you are allowed to add any include directive. You are not allowed to include string, cstdlib or math libraries. Also, you are not allowed to use any built-in functions of c-strings. can someone help with the third, fourth, and fifth functions? I tried many ways but i cannot figure...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation , all numbers must be between 0 and 100) 2) find the largest number 3) Find the Smallest Number 4) Find the Sum of all numbers in the Array Display: as per the user's section (menu using switch or if else ) Largest Number Smallest Number Sum of all numbers the original Array DO NOT USE METHODS OR FUNCTIONS Submit: Source code (C++) output...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files 1. WriteaclassGradeBookcontainingthefollowing: Private attributes: - courseName: a string representing the name of the course. - nbOfStudents: an integer representing the number of students enrolled in the course. The number of students is greater than or equal to 5. - grades: a double dimensional array of integers representing the grades of Test1, Test2 and Final of every student. It should be a dynamic array. Public...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions with arguments. Create programs with small functions where main goes to a series of functions where the real work takes place. Don’t use global variables and don’t use break within a loop (unless working with a switch statement). Functions can’t have more than 30 statements of code, not including comments, blank lines, or variable definitions. Don’t use a return in the middle of the...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
A DNA strand is represented by a string of the characters A, C, G, and T,...
A DNA strand is represented by a string of the characters A, C, G, and T, each of which represents a nucleotide. Each nucleotide has its complement as indicated by this Ruby hash: NUCLEOTIDE_COMPLEMENT = { 'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C' } The reverse-complement of a DNA string is a new string in which each nucleotide is replaced by its complement and the string is reversed. Reverse-complements are important in bioinformatics since a...
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT