473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C++ classes are hard please help us.

3
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
Jul 3 '07 #1
4 1299
sicarie
4,677 Expert Mod 4TB
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
Jul 3 '07 #2
helpus
3
this is what i have so far.


can you help me finish part one?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void random()
  5. {
  6.  
  7.  
  8.     char term;
  9.     char ary[100];
  10.     ary[60] = 0;
  11.     int i;
  12.     i = 0;
  13.  
  14.     while (i < 59)
  15.         {        
  16.             ary[i] = rand() % 122 + 1;
  17.             while (ary[i] < 97) 
  18.                 ary[i] = rand() % 122 + 1;
  19.             i = i + 1;
  20.         }
  21.     cout << ary << endl;
  22. }


and this is what i have for part 2.

can you help me finish part 2?

Expand|Select|Wrap|Line Numbers
  1. void sentence() 
  2. {
  3.     char l;
  4.     char phrase[20];
  5.  
  6.  
  7.  
  8.     cout << "Enter a phrase: ";
  9.     cin.ignore();
  10.     cin.getline(phrase,20);
  11.  
  12.  
  13.     cout << "enter a terminating letter: " << endl;
  14.     cin >> l;
  15.  
  16.     cout << phrase << endl;
  17.     cout << l << endl;
  18.  
  19. }
Jul 3 '07 #3
sicarie
4,677 Expert Mod 4TB
What are you stuck on?

And please have a look at this, this, and these.
Jul 3 '07 #4
helpus
3
for part one i cant figure out how to find the max and min stuff. can you help me

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. void main()
  8. {
  9.  
  10.     int N, y, x, z, i;
  11.     char array[60];
  12.     ofstream fout;
  13.     fout.open("midterm1.txt");
  14.         if (fout.fail())
  15.         {
  16.             cout << "File cannot be created" << endl;
  17.         }
  18.         cout << "Enter the number of columns between 1 & 60" << endl;
  19.         cin >> N;
  20.  
  21.         i = 0;
  22.             while (i<= 59)
  23.             {
  24.                 array[i] = rand() % 122 +1;
  25.                 while (array[i] < 97) 
  26.                 {
  27.                     array[i] = rand() % 122 +1;
  28.                 }
  29.                 i = i+1;
  30.             }
  31.             x = 0;
  32.  
  33.             while (x < N)
  34.             {
  35.                 z = (60 / N) * x;
  36.                 y = 0;
  37.                 while (y < (60 / N))
  38.                 {
  39.                     cout << array[z + y];
  40.                     fout << array[z + y];
  41.                     y = y+1;
  42.                 }
  43.                 fout << endl;
  44.                 cout << endl;
  45.                 x = x + 1;
  46.             }
  47.             fout.close();
  48. }
Jul 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
3
by: Logan K. | last post by:
What is a PHP class? I've seen a lot of talk about these and how they can help you out, but I've never seen a very good explanation. I've been working with PHP for just over 6 months and usually...
5
by: Hal Vaughan | last post by:
I think a lot of this is definately a question of personal programming style, but I'm new to Java and would like to hear a few opinions. I'm writing a control panel for an application that runs...
8
by: Corey Lubin | last post by:
someGlobal=1 class Original: def foo(self): # Make use of someGlobal from original import * someGlobal=2
9
by: Jack | last post by:
Hello I have a library of calculationally intensive classes that is used both by a GUI based authoring application and by a simpler non-interactive rendering application. Both of these...
13
by: Simon Dean | last post by:
Hi, I have a couple of questions. If you don't mind. Sorry, I do get a bit wordy at times. First one just throws some thoughts around hoping for answers :-) 1) Anyone got a theory on the...
2
by: Amu | last post by:
i have a dll ( template class) ready which is written in VC++6. But presently i need to inherit its classes into my new C#.net project.so if there is some better solution with u then please give me...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
7
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.