473,480 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting a class as a parameter?

4 New Member
Hey All,
I have a quick question on an assignment I have to do

I need to be able to write a function that takes an input stream and a video(from a class Video), out of 4 total video variables, as a parameter. The function that i called "inputVideo" is supposed to read information from the input stream into the video parameter. We are not supposed to do any prompting in the function.

So far I only know how to take an input stream as a parameter, but I'm getting really confused on how to take a video as one and then read the information from one to the other, without prompting in the function.

Also I'm confused on how to call the function in main.

Here is some code I have written out that uses the class and such that is directly in main:

Expand|Select|Wrap|Line Numbers
  1. cout << "Please enter the information for your video in the following format: "
  2.        << endl;
  3.        << "The title, the number of videos owned, number of videos available:" 
  4.        << endl;
  5.  
  6. //read info. from video1 and put info. into it
  7.     while (isspace(cin.peek()))
  8.         cin.ignore();
  9.     getline(cin, temp);
  10.     video1.setTitle(temp);
  11.     cin >> tempint;
  12.     video1.setNumOwned(tempint);
  13.     cin >> tempint2;
  14.     video1.setNumAvailable(tempint2);
What I'm trying to figure out now is how to still prompt the user in main, like above, and then use the "inputVideo" function to read the information from the keyboard.

Any help would be greatly appreciated.
Thanks,

mrspiff
Jul 29 '07 #1
5 4080
ilikepython
844 Recognized Expert Contributor
Hey All,
I have a quick question on an assignment I have to do

I need to be able to write a function that takes an input stream and a video(from a class Video), out of 4 total video variables, as a parameter. The function that i called "inputVideo" is supposed to read information from the input stream into the video parameter. We are not supposed to do any prompting in the function.

So far I only know how to take an input stream as a parameter, but I'm getting really confused on how to take a video as one and then read the information from one to the other, without prompting in the function.

Also I'm confused on how to call the function in main.

Here is some code I have written out that uses the class and such that is directly in main:

Expand|Select|Wrap|Line Numbers
  1. cout << "Please enter the information for your video in the following format: "
  2.        << endl;
  3.        << "The title, the number of videos owned, number of videos available:" 
  4.        << endl;
  5.  
  6. //read info. from video1 and put info. into it
  7.     while (isspace(cin.peek()))
  8.         cin.ignore();
  9.     getline(cin, temp);
  10.     video1.setTitle(temp);
  11.     cin >> tempint;
  12.     video1.setNumOwned(tempint);
  13.     cin >> tempint2;
  14.     video1.setNumAvailable(tempint2);
What I'm trying to figure out now is how to still prompt the user in main, like above, and then use the "inputVideo" function to read the information from the keyboard.

Any help would be greatly appreciated.
Thanks,

mrspiff
Try something like this:
Expand|Select|Wrap|Line Numbers
  1. void inputVideo(istream &theStream, Video &theVideo)
  2. {
  3.     int x;
  4.     theStream >> x;
  5.     theVideo.value = x;
  6. }
  7.  
I don't really understand how you will prompt for the variable in main and at the same time read it from the keyboard in inputVideo. By prompt do you mean display a message?:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     Video video1;
  4.     cout << "Please enter a value: ";
  5.     inputVideo(cin, video1);
  6.  
  7.     return 0;
  8. }
  9.  
Jul 29 '07 #2
mrspiff
4 New Member
Yes, that is exactly what I don't understand either. Your first code post is what I thought we had to do, but when looking at the directions I get confused.

Here is what the directions say:

Write a function, inputVideo, that takes an input stream and a video as a parameter. This funtion should have a precondition that the input stream is open. The function should read information from the input stream into the video parameter. The function should NOT do any prompting.

(by prompting I assume not asking for variables.)

(in main)
Prompt the user to enter the information for video3, then use the inputVideo to read information from the keyboard into video3.

Any idea?
Jul 29 '07 #3
mrspiff
4 New Member
To top it off there is also an output function "outputVideo" that should be included also. Using the same parameters that should output the video information to the screen...

Hope that helps
Jul 30 '07 #4
sicarie
4,677 Recognized Expert Moderator Specialist
I would recommend pseudocoding the individual functions. If you pseudocode your main, you don't have to worry about the implementation of your functions, just what you pass and return to them. Then you can pseudocode them later - that helps cut down on everything you have to keep in your head. For example, your first function, you are given an fstream. You don't care where it came from, you just have it, you want to check it to make sure it is open, and then use it.

Does that help, or do you have a more specific algorithm question?
Jul 30 '07 #5
mrspiff
4 New Member
Yeah, I get the idea....

An example would help a ton though.
Jul 30 '07 #6

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

Similar topics

5
8292
by: Laura | last post by:
Hello, Newbie question: Does anyone know how to dynamically set the screen width in an applet? I have an applet that creates a horizontal bar menu on a webpage, and I would like the width to be...
2
2209
by: J Krugman | last post by:
I have a form with a couple of submit buttons, plus a "pseudolink" that is also supposed to submit the form; the submitted form data feeds to a CGI script. The two submit buttons have the name...
0
1561
by: Rhino | last post by:
I am working with SQL Functions in DB2 for Windows/Linux/UNIX (V8.2.1) and am having a problem setting input parameters for SQL Functions to null in the Development Center. My simple function,...
2
3732
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among...
3
1002
by: Dave | last post by:
If I have a name of a User Control in my project, how can I set an Object to that User Control? ie; I have a User Control, called "Accounts" in my project I tried the following code ...
1
6432
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
1287
by: anathema | last post by:
this is not specifically behaviour related, but i thought i would risk asking anyway. i am working on a script that triggers a blind down or blind up effect by clicking on a particular link. it...
5
5279
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
41
2822
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
0
7046
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
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7088
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...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.