C++ :: Finding Most Common Character Within A String
Oct 24, 2013
I am trying to take a string that is within the main function, and write a void function that gives me the most common alpha character used inside the string. How to mix a string and an array together like that as I am not too familiar with arrays yet.
View 8 Replies
May 17, 2014
the code shows all characters frequency, however i want to find which one has highest frequency for example cprogrammmmming cboard highest frequency: m
char string[100], ch;int c =0, count[26]={0};
printf("Enter a string");
gets(string);
[Code].....
View 8 Replies
View Related
Jan 2, 2015
Is there a function or algorithm in stl in c++ the gcd of a vector ?
View 1 Replies
View Related
Feb 23, 2013
how assignments is to write code that returns a value that is repeated more than once in an array of 8 integers.For example:
Numbers: 30 12 100 33 2 2 1 40
Output: 2
Here is my code so far:
Code:
#include <stdio.h
int main(void){
int i;
int j;
int arr[8];
int count;
int maxCount = 0;
int maxValue = 0;
[code]....
When I compile this code (on Vim), I get an error when I print the array of 8 above (see ERROR above).
View 3 Replies
View Related
Apr 13, 2014
I have a class 'A' which is almost perfect for my needs. Class 'B' uses class 'A' I've now designed Class 'C' and Class 'D' and noticed that there is a good chunk of code in class 'B', 'C' and 'D' for using Class 'A' is duplicated. I've separated out this code in specific, standalone functions in each of the classes. Now I'm wondering where this code should go. At the moment, the functions are duplicated in the three calling classes (B, C and D). Placing the functions into class 'A' would break the single responsibility principle. Inheritance to add functionality would likely break both SRP and LSP. The one that seems that it may work is composition.
However, Is designing a complete class just for a few functions over kill?
Would it be valid for classes 'B', 'C' and 'D' to access both the new class 'E' (which would depend on A) and the old class 'A' (which would have to be the same instance as the instance in the new class 'E'), or should the new class 'E' provide sufficient functionality so that Classes B, C and D don't need to access Class A directly? It would seem that its then an incomplete interface of the original object with additional functionality (ie, incompatible) Or should I do it a completely different way?
View 4 Replies
View Related
Sep 13, 2014
So I'm trying to create a function that replaces any instance of a character in a string with another. So first I tried the replace() string member function:
In my implementation file
void NewString::ReplaceChar(const char& target,const char& entry)
{
this->replace(this->begin(),this->end(), target, entry);
};
Main program
#include "NewString.h"
using namespace ...;
int main()
[Code].....
Instead of replacing the the l's with y's it outputted a long string of y's. Also, NewString is derived from the string class (it's for the assignment). the header and whole implementation file, already tested.
I've also tried, instead, to use a for loop in ReplaceChar() but I need to overload the == operator and I don't know how I should exactly:
bool NewString::operator ==(const char& target)const {
if(*this == target)
return true;
[Code]....
I want the == operator to test if the value in the char array is equal to target but I'm not sure how to pass in the position. I'm guessing the this pointer in ReplaceChar() is not the same as the one dereferenced in ==() because target is never replaced by entry in the string.
View 5 Replies
View Related
Sep 8, 2014
I need to find a string with leading spaces like " target sting" inside another sting.
And I need to find something like "target sting" inside another sting.
I used .IndexOf() but noticed it ignores leading spaces.
So then I went with .Substring() but that doesn't seem like that's the best solution either.
View 5 Replies
View Related
Jul 6, 2014
Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '