Write a C program Have the user enter a number from 1 to 80

Write a C++ program, & Have the user enter a number from 1 to 80, then print out a string of random letters (a thorough z) of that length. Then make a table of the occurrences of each letter in your random string.

F4. File Edit View State Window Help Stdin/Stdout/Stderr How many letters do you want in your random string? 52 tcsewulxfrxgfpghhzehijgoipqnpirhunbaddoletijlrtizyoo Letters a b c d e f g h i j k 1 m n o p q r s t u u w x y z No of occurances 1 1 1 2 3 2 3 4 5 2 3 0 2 4 3 1 3 1 3 1 1 1 2 1 2 Finished

Solution

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
static const char alph_string[]=\"abcdefghijklmnopqrstuvwxyz\";
int main()
{
   int len,i,j,count;
   char key;
   char str[100]=\" \";
   cout << \"how many letters do you want in your random string? \";
cin >> len;
   for(i=0;i<len;i++)
       str[i]=alph_string[rand() % (sizeof(alph_string)-1)];
   char str_array[]={\'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'h\',\'i\',\'j\',\'k\',\'l\',\'m\',\'n\',\'o\',\'p\',\'q\',\'r\',\'s\',\'t\',\'u\',\'v\',\'w\',\'x\',\'y\',\'z\'};
   cout << str << endl;
   for(i=0;i<26;i++)
       cout << str_array[i] << \" \";
       cout << endl;
   for(i=0;i<26;i++)
   {
       key=str_array[i];
       count=0;
       for(j=0;j<len;j++)
       {
           if(key==str[j])
               count++;
       }
       cout << count << \" \";
   }
   return 0;
}

Write a C++ program, & Have the user enter a number from 1 to 80, then print out a string of random letters (a thorough z) of that length. Then make a table

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site