473,395 Members | 1,595 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,395 software developers and data experts.

Movie Ticket Program. struct, ifstream

I have assignment to do, but i dont know how to start it off. I read from a text file( also print movies r playing first) , read each line and assign to each string and next line is the price so and customer should be able to choose a more then one movie, and at the end print the add up the price with tax(5%). can some one help me please. Thankx alot in advance.

so here is the output should be like

This is my movie.txt file


Expand|Select|Wrap|Line Numbers
  1. Transformers                       
  2. $8.50
  3. Rush Hour 3                        
  4. $8.50
  5. The Game Plan                   
  6. $9.50
  7.  
  8.  
This is Output I want.
Expand|Select|Wrap|Line Numbers
  1. Movies that are Playing now:
  2.  
  3. Transformers                       $8.50
  4. Rush Hour 3                        $8.50
  5. The Game Plan                   $9.50
  6.  
  7. Your Movie Ticket:
  8.  
  9. Rush Hour 3                        $8.50
  10. The Game Plan                   $9.50
  11.  
  12. Total:                                 $18.00
  13. Tax:                                   $0.90
  14. Amount Due:                      $18.90
  15.  
  16.  
Oct 4 '07 #1
15 5175
Savage
1,764 Expert 1GB
I have assignment to do, but i dont know how to start it off. I read from a text file( also print movies r playing first) , read each line and assign to each string and next line is the price so and customer should be able to choose a more then one movie, and at the end print the add up the price with tax(5%). can some one help me please. Thankx alot in advance.

so here is the output should be like

This is my movie.txt file


Expand|Select|Wrap|Line Numbers
  1. Transformers                       
  2. $8.50
  3. Rush Hour 3                        
  4. $8.50
  5. The Game Plan                   
  6. $9.50
  7.  
  8.  
This is Output I want.
Expand|Select|Wrap|Line Numbers
  1. Movies that are Playing now:
  2.  
  3. Transformers                       $8.50
  4. Rush Hour 3                        $8.50
  5. The Game Plan                   $9.50
  6.  
  7. Your Movie Ticket:
  8.  
  9. Rush Hour 3                        $8.50
  10. The Game Plan                   $9.50
  11.  
  12. Total:                                 $18.00
  13. Tax:                                   $0.90
  14. Amount Due:                      $18.90
  15.  
  16.  
Which part of this you cannot figure out?

Savage

PS:Please read our posting guidelines
Oct 4 '07 #2
Which part of this you cannot figure out?

Savage

PS:Please read our posting guidelines

Like how to start off da program. i could get struct fuction in put file, i could get to da point where it will print whole file in screen but i dont kno whow to get each line and assingt it to each string. like let say
Expand|Select|Wrap|Line Numbers
  1. struct movieNametype
  2.      {
  3.           char movieName [ ]
  4.           double price;
  5.      }
  6.  
  7. movieItemtype movies[30];
so let say
Expand|Select|Wrap|Line Numbers
  1. ifstream InFile;
  2. InFile.open ("movies.txt");
so here is the question how do i get to read each line from "movies.txt" file and assign it like this
Expand|Select|Wrap|Line Numbers
  1. movies[0].movieName="Rush Hour 3";
  2. movies[0].price=8.50;
and this repeats until to end of it.
Oct 4 '07 #3
Savage
1,764 Expert 1GB
Like how to start off da program. i could get struct fuction in put file, i could get to da point where it will print whole file in screen but i dont kno whow to get each line and assingt it to each string. like let say

struct movieNametype
{
char movieName [ ]
double price;
}

movieItemtype movies[30];
so let say
ifstream InFile;
InFile.open ("movies.txt");
so here is the question how do i get to read each line from "movies.txt" file and assign it like this
movies[0].movieName="Rush Hour 3";
movies[0].price=8.50;

and this repeats until to end of it.
See this

Savage
Oct 4 '07 #4
Yea i read that before, but i dont get it how to read from file and assign to string line by line.
Oct 4 '07 #5
sicarie
4,677 Expert Mod 4TB
Yea i read that before, but i dont get it how to read from file and assign to string line by line.
You're going to need an array of strings, and if you can't read that and figure out how to read from a file, you're going to have to tell us why you don't understand that - we can't read your mind and figure out what you're stuck on.
Oct 4 '07 #6
okay, let say


cout<<"movie name: ";
cin>>movie_name;

okay so how do i get each line from a file (movies.txt) and
cin>>movies[0].movieName;

so if first line in file says Rush hour 3
it should be stored in movies[0].movieName
.. i guess i explained ma self this time?
Oct 4 '07 #7
sicarie
4,677 Expert Mod 4TB
okay, let say


cout<<"movie name: ";
cin>>movie_name;

okay so how do i get each line from a file (movies.txt) and
cin>>movies[0].movieName
Yep. That's pretty much exactly it, only in a loop so that you pull the line in to a different spot in the array each time, and you test that the file hasn't reached the end. You'll probably want to increment the array index, and you're not using cin. I believe there's another that might be better for C++, let me look it up.

But aside of that (and having looked at the getline page) do you understand it? If not, can you post the line you're having trouble with?
Oct 4 '07 #8
#include <fstream>

fstream InFile;
char str[2000];
InFile.open ("C:\Documents and Settings\%username%\Desktop\movie_c\movie.txt",ios ::in);
while (!InFile.eof())
{
InFile.getline(str,2000);
cout<<str;
}

it compiles but, i dont get any output in screen?
Oct 4 '07 #9
Savage
1,764 Expert 1GB
it compiles but, i dont get any output in screen?
Have you added:

Expand|Select|Wrap|Line Numbers
  1. system("PAUSE"); 
at the end??

Savage
Oct 5 '07 #10
Have you added:

Expand|Select|Wrap|Line Numbers
  1. system("PAUSE"); 
at the end??

Savage
yea,, i have getch(). wat i ment i dont get anything on screen for output is dat... i dont get any output. screen is there but No OUTPUT whatsoever.
Oct 5 '07 #11
sicarie
4,677 Expert Mod 4TB
You need to post the code - we're sitting here guessing and giving you functions, but we've seen no implementation. If you're not getting output, are you getting errors? Are you printing stuff out, or are you printing stuff to a file? I know you're reading in from a file (wasn't that in your original problem?), so are you printing it out after that, or are you just performing some action (adding movie to db, removing from collection, throwing it against the wall, etc...) and then not printing to standard output (cout) the success or failure of that?
Oct 5 '07 #12
You need to post the code - we're sitting here guessing and giving you functions, but we've seen no implementation. If you're not getting output, are you getting errors? Are you printing stuff out, or are you printing stuff to a file? I know you're reading in from a file (wasn't that in your original problem?), so are you printing it out after that, or are you just performing some action (adding movie to db, removing from collection, throwing it against the wall, etc...) and then not printing to standard output (cout) the success or failure of that?
Code that i have in my previous post. datz one i am useing to read from jst file and print out thats it. same code. it compiles everything no error, but in OUTPUT SCREEN, nutthing prints on it. so i dont know what is the problem there because, there is no error or anything it just doesnt print anything on it.
Oct 5 '07 #13
sicarie
4,677 Expert Mod 4TB
Can you post your whole program?
Oct 6 '07 #14
Can you post your whole program?
Expand|Select|Wrap|Line Numbers
  1. {
  2.  
  3.     char str[2000];
  4.     fstream file_op("C:\Documents and Settings\Administrator\Desktop\menu_c\menu.txt",ios::in);
  5.         while(!file_op.eof())
  6.         {
  7.               file_op.getline(str,2000);
  8.               cout <<str;
  9.         }         file_op.close();
  10.         cout <<endl;
  11.  
  12.  
  13. }
Oct 6 '07 #15
sicarie
4,677 Expert Mod 4TB
First of all, you need to put 'using namespace std;' after your library declarations.

Expand|Select|Wrap|Line Numbers
  1.     fstream file_op("C:\Documents and Settings\Administrator\Desktop\menu_c\menu.txt",ios::in);
  2.  
Then, I believe this is your problem, you need to be backwhacking the filepath - the compiler interprets a single backslash as an escape character so you can use things like \n, \t, etc... which are newline and tab characters. So your compiler is trying to figure out what \D, \A, \m mean, etc... So you need C:\\Documents and Settings\\yourpath\\your file.

PS - as we have a policy against posting full code, I've snipped it down, but that's just due to the forum rules.
Oct 8 '07 #16

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

Similar topics

3
by: JasBascom | last post by:
I have written a program that is suppose to compare to lines c12345 I04567 the program takes the first digit encountered of both lines, decides which one is smaller and writes that to a file...
3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
2
by: JasBascom | last post by:
I thought it was too much to put this program in with my last message. The program compiles ok, but when I execute, I get access errors. can someone put it through their compiler please. I think...
6
by: Baloff | last post by:
Hello I wrote a code which is suppose to read a file which contains lines of double and prints it out. thanks for helping double.txt*************************************** 1.01 2.0301
0
by: soulhack | last post by:
Hey! Im working on a movie list, but i donīt get the delete part of it to work. Help please :p Many thanks//SoulHack # include <iostream.h> # include <conio.h> # include <string.h> #...
9
by: gdarian216 | last post by:
I have written a c++ program that takes input from a file and outputs the average. The program uses structs and I need to convert the struct to a class. I just dont know how to get started and if...
2
by: gdarian216 | last post by:
the program reads input from a file and then outputs the averages and grade. for some reason it is reading in the same line twice and it doesn't print out the grade. everything else is correct, if...
4
by: charmeda103 | last post by:
i have this program that i am almost done with, i am one part away from being done. the last part is putting the results together; here is the results that i need to put in code. do u have any...
0
by: charmeda103 | last post by:
when i run my program it runs with no erorrs but the output screen is giving me strange results here is whats its giving me: CONFERENCE OVERALL RANK TEAM W-L % WINS MARGIN W-L ...
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: 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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.