• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ question

Kur

Senior member
taking a C++ class and for one of my labs I'm a little confused, I don't know where to look up how to do this. Please I DO NOT want this completed for me. I would like a kick in the right direction, possibly explain more about what the lab is talking about. I would ask my teacher but my classes are monday and wednesday and hes not in his office on the weekends.

Write a program that will have 4 functions:
- input an array
void inputData( istream &, int [], int);
- print an array
void printData( ostream &, const int [], int);
- copy one array to another array in normal order
void copyArray( const int orig[], int dup[], int);
- copy one array to another array in reverse order
void revCopy( const int orig[], int rev[], int);
Write the main program to test the four functions you wrote

The book I have (GG college books) talks about this stuff very little and exspects the teacher to fill in the blanks. Because the class is in the summer we cover 2-3 chapters in one class so sometimes it's alot of handle. here are the questions I have.

What does the istream and ostream mean?
int [] and cont int [] and all those, what do those mean?

I know this is supposed to be an array function just kinda lost, any kicks in the right directiong would be great, even any hints.
 
istream is an input stream and ostream an output stream. These can be files or console in and out (cout, cin)
int[] is an array of integers
const int[] indicates that the input parameter doesn't change
 
Originally posted by: Thyme
istream is an input stream and ostream an output stream. These can be files or console in and out (cout, cin)
int[] is an array of integers
const int[] indicates that the input parameter doesn't change

i thought fstream was for files, and istream and ostream were strictly console in and out.
 
Originally posted by: Acanthus
Originally posted by: Thyme
istream is an input stream and ostream an output stream. These can be files or console in and out (cout, cin)
int[] is an array of integers
const int[] indicates that the input parameter doesn't change

i thought fstream was for files, and istream and ostream were strictly console in and out.

fstreams are a kind combination istream and ostream (i.e. iostream). istream and ostream define how "streams" are expected to work and aren't specifically linked to the console. cout and cin are global streams and ostreams objects that read/write from the console.

So basically what this means is, if you are given a fstream you can do anything you would do to cout and cin on the fstream.

What this allows you to do is to define a function like this:

void readInput(istream & in) {}

and use that to read input from either a file or the console (or any other kind of stream).

Makes sense?
 
void revCopy( const int orig[], int rev[], int);

Try to have some fun with this one. If you know pointers and play with them a bit, you can find some pretty creative solutions. Here is an example that will not directly solve the problem but would explain what I am referring to (it is the source code for a common string copy function in c so I would think this is fair game): http://fxr.watson.org/fxr/source/libkern/strcpy.c
 
Back
Top