C++ classes are hard please help us.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helpus
    New Member
    • Jul 2007
    • 3

    #1

    C++ classes are hard please help us.

    Menu Option one:

    This function should create a 1-D array of size 60 containing randomly generated letters within the range [a, z]. Determine a) the maximum and minimum values and b) the indices of their first occurrence and c) the number of times each occurs. Write the values, number of occurrences, and indices to the output file (midterm1.txt) in a user-specified rectangular format – that is, the user will supply a valid number of rows.

    NOTES: You will need to perform the following operations

    Initialize the array - fill the array with random letters in the appropriate range between a and z
    Determine the max, the array index of its first occurrence and the number of times it occurs
    Determine the min, the array index of its first occurrence and the number of times it occurs
    Prompt the user for a valid number of rows N such that 60/N is an integer
    Write the contents of the array to the file (midterm1.txt) with N letters per line. (eg. 4 x 15, 10 x 6, etc.)

    Menu Option two:

    Continually prompt the user for a phrase (sentence) and then for a letter (to be used as a terminating character) until the user enters the phrase “stop”. Search each phrase for the first occurrence of the terminating character in the phrase and modify the phrase so it ends with the character preceding the user’s chosen terminating character. Write the modified phrase out to the screen. In the event that the letter does not appear in the phrase write an appropriate informational message.

    Example: (italics indicate user entered information and non-italics indicate your program’s output)
    The cow jumped over the moon
    u
    The cow j

    Hello there
    X
    The letter X does not appear in the entered phrase

    stop
    You have chosen to stop, goodbye
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. You have not asked a question. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • helpus
      New Member
      • Jul 2007
      • 3

      #3
      this is what i have so far.


      can you help me finish part one?

      [code=cpp]
      #include <iostream>
      using namespace std;

      void random()
      {


      char term;
      char ary[100];
      ary[60] = 0;
      int i;
      i = 0;

      while (i < 59)
      {
      ary[i] = rand() % 122 + 1;
      while (ary[i] < 97)
      ary[i] = rand() % 122 + 1;
      i = i + 1;
      }
      cout << ary << endl;
      }[/code]



      and this is what i have for part 2.

      can you help me finish part 2?

      [code=cpp]
      void sentence()
      {
      char l;
      char phrase[20];



      cout << "Enter a phrase: ";
      cin.ignore();
      cin.getline(phr ase,20);


      cout << "enter a terminating letter: " << endl;
      cin >> l;

      cout << phrase << endl;
      cout << l << endl;

      }[/code]
      Last edited by sicarie; Jul 3 '07, 05:18 PM. Reason: Please use [code=cpp] and [/code] tags around your code.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        What are you stuck on?

        And please have a look at this, this, and these.

        Comment

        • helpus
          New Member
          • Jul 2007
          • 3

          #5
          for part one i cant figure out how to find the max and min stuff. can you help me

          [code=cpp]
          #include <iostream>
          #include <fstream>
          using namespace std;



          void main()
          {

          int N, y, x, z, i;
          char array[60];
          ofstream fout;
          fout.open("midt erm1.txt");
          if (fout.fail())
          {
          cout << "File cannot be created" << endl;
          }
          cout << "Enter the number of columns between 1 & 60" << endl;
          cin >> N;

          i = 0;
          while (i<= 59)
          {
          array[i] = rand() % 122 +1;
          while (array[i] < 97)
          {
          array[i] = rand() % 122 +1;
          }
          i = i+1;
          }
          x = 0;

          while (x < N)
          {
          z = (60 / N) * x;
          y = 0;
          while (y < (60 / N))
          {
          cout << array[z + y];
          fout << array[z + y];
          y = y+1;
          }
          fout << endl;
          cout << endl;
          x = x + 1;
          }
          fout.close();
          }[/code]
          Last edited by JosAH; Jul 3 '07, 09:14 PM. Reason: added those code tags again

          Comment

          Working...