sometimes it helps to have code to start with if your stuck. here is an example code for you maybe you can modify it in the way you need #include <iostream>
#include <ctime>
#include "RandomCharacter.h"
using namespace std;
const int NUMBER_OF_RANDOM_LETTERS = 100;
void createArray(char []);
void displayArray(const char []);
void countLetters(const char [], int []);
void displayCounts(const int []);
int main()
{
// Declare and create an array
char chars[NUMBER_OF_RANDOM_LETTERS];
// Initialize the array with random lowercase letters
createArray(chars);
// Display the array
cout << "The lowercase letters are: " << endl;
displayArray(chars);
// Count the occurrences of each letter
int counts[26];
// Count the occurrences of each letter
countLetters(chars, counts);
// Display counts
cout << "\nThe occurrences of each letter are: " << endl;
displayCounts(counts);
return 0;
}
// Create an array of characters
void createArray(char chars[])
{
// Create lowercase letters randomly and assign
// them to the array
srand(time(0));
for (int i = 0; i < NUMBER_OF_RANDOM_LETTERS; i++)
chars[i] = getRandomLowerCaseLetter();
}
// Display the array of characters
void displayArray(const char chars[])
{
// Display the characters in the array 20 on each line
for (int i = 0; i < NUMBER_OF_RANDOM_LETTERS; i++)
{
if ((i + 1) % 20 == 0)
cout << chars[i] << " " << endl;
else
cout << chars[i] << " ";
}
}
// Count the occurrences of each letter
void countLetters(const char chars[], int counts[])
{
// Initialize the array
for (int i = 0; i < 26; i++)
counts[i] = 0;
// For each lowercase letter in the array, count it
for (int i = 0; i < NUMBER_OF_RANDOM_LETTERS; i++)
counts[chars[i] - 'a'] ++;
}
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
int main()
{
std::string a("The school 7x8 is a nice place. 7x8 is very popular.");
std::string b("LSU");
std::vector<int> locations;
for (int i = 0; i < a.size(); ++i)
{
locations.push_back(a.find("7x8", i));
}
for (int i = 0; i < locations.size(); ++i)
{
std::copy(b.begin(), b.end(), a.begin() + locations[i]);
}
std::cout << a << std::endl;
return 0;
}