473,406 Members | 2,816 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,406 software developers and data experts.

Read From file c++ SEquential files

I am trying to read and display the contents of my file but with no luck.oMy view all function doesnt display anything. That function is nt completed, was just testing it view some of info
Here's my driver code

Expand|Select|Wrap|Line Numbers
  1. #include"Animal.h"
  2. #include"Client.h"
  3. #include"Removal.h"
  4. #include"Date.h"
  5. #include"Animal.h"
  6. #include"TelNo.h"
  7. #include"Time.h"
  8. #include"Address.h"
  9. #include"Intervention.h"
  10. #include <iomanip>
  11. #include<iostream>
  12. #include<istream>
  13. #include<string>
  14. #include<stdio.h>
  15. #include<stdlib.h>
  16. #include <fstream>
  17. #include<ostream>
  18.  
  19. using namespace std;
  20.  
  21.  
  22. void Mainmenu();
  23. void Showclinic();
  24. void addVisit(string, Intervention);
  25. void ViewAll();
  26.  
  27.  
  28. int main()
  29. {
  30.  
  31.     Mainmenu();
  32.     return 0;
  33. }
  34.  
  35. void Mainmenu()
  36. {
  37.     int option;
  38.  
  39.  
  40.     cout << "1: Clinic Visit\t\t";
  41.     cout << "2: Removal\t\t";
  42.     cout << "3: Exit Visit\t\t\n";
  43.     cout << "Select an option\n\n\n";
  44.     cin >> option;
  45.     system("cls");
  46.  
  47.     switch (option)
  48.     {
  49.     case 1:        
  50.         Showclinic();
  51.             break;
  52.     case 2: //RemAnimal();
  53.  
  54.         break;
  55.     case 3:
  56.  
  57.         exit(0);
  58.         break;
  59.     default:
  60.         cout << "unknown option";
  61.     }
  62.  
  63. }
  64.  
  65.  
  66. void Showclinic()
  67. {
  68.     int x;
  69.     Intervention inte;
  70.  
  71.     cout << "1: ADD\n\n";
  72.     cout << "2: UPDATE\n\n";
  73.     cout << "3: VIEW\n\n";
  74.     cout << "4: VIEW ALL\n\n";
  75.     cout << "5: DELETE\n\n";
  76.     cout << "6: Exit\n\n";
  77.     cout << "Enter Choice\n";
  78.     cin >> x;
  79.     switch (x)
  80.     {
  81.     case 1:
  82.         system("cls");
  83.         cout << "CURRENTLY ADDING DATA\n";
  84.         addVisit("JSPCA.txt", inte);
  85.  
  86.         break;
  87.     case 2:
  88.         cout << "UPDATE";
  89.         system("cls");
  90.         break;
  91.     case 3:
  92.         cout << "VIEW";
  93.         system("cls");
  94.         break;
  95.     case 4:system("cls");
  96.         cout << "VIEW ALL RECORDS ON FILE\n";
  97.         ViewAll();
  98.         //inte.display();
  99.         system("pause");
  100.         break;
  101.     case 5:system("cls");
  102.         cout << "DELETE";
  103.         system("cls");
  104.         break;
  105.     case 6:
  106.         cout << "EXIT";
  107.  
  108.         exit(0);
  109.         break;
  110.     default:
  111.         cout << "value of x unknown";
  112.     }
  113. }
  114. //***********************************************************************
  115. void addVisit(string name, Intervention inte)
  116. {
  117.     int hour, min, day, month, yr, snum, age;
  118.     string fname, lname, interNo, problem, clinic, area, ex, li, type, breed, gender, sname, town, pay;
  119.  
  120.     cout << "Enter new intervention number\n";
  121.     cin >> interNo;
  122.  
  123.     // user enters information, which is copied into file
  124.     cout << "Enter name of clinic(Winchester or Caymanas)\n ";
  125.     cin >> clinic;
  126.     cout << "Enter lastname, firstname\n ";
  127.     cin >> lname;
  128.     cin >> fname;
  129.     cout << "Please Address(Street#, Street Name, Town)\n";
  130.     cin >> snum >> sname >> town;
  131.     cout << "Enter Contact#:(area exchange line)\n";
  132.     cin >> area >> ex >> li;
  133.     cout << "Enter Animal Type, Breed,Gender and Age\n";
  134.     cin >> type >> breed >> gender >> age;
  135.     cout << "Please specify problem\n";
  136.     cin >> problem;
  137.     cout <<( "Please enter letter for payment type:\n");
  138.     cout << ("Full=F\n");
  139.     cout << ("Contribution=C\n");
  140.     cout << ("Can't Pay=CP\n");
  141.     cin >> pay;
  142.     cout << "Enter date in format month dd mm yyyy\n";
  143.     cin >> day >> month >> yr;
  144.     cout << "Enter the time(hour minute\n)";
  145.     cin >> hour >> min;
  146.         // set record InterventionNo, Client,animal, date and time values
  147.         //inte.setInterventionNo(input);
  148.         inte.setClient(Client(fname, lname, pay,interNo,clinic));
  149.         inte.setAddress(Address(snum, sname, town));
  150.         inte.setTelNo(TelNo(area, ex, li));
  151.         inte.setAnimal(Animal(type, breed, gender, age, problem));
  152.         inte.setDate(Date(day, month, yr));
  153.         inte.setTime(Time(hour, min));
  154.  
  155.  
  156.         ofstream clientfile(name, ios::app);
  157.         if (clientfile)
  158.         {
  159.             clientfile << inte.getClient().getInterventionNo() << "";
  160.             clientfile << inte.getClient().getClinic() << "";
  161.             clientfile << inte.getClient().getFname() << "";
  162.             clientfile << inte.getClient().getLname() << "";
  163.             clientfile << inte.getClient().getPayment() << "";
  164.             clientfile << inte.getAddress().getStreetNo() << "";
  165.             clientfile << inte.getAddress().getStreetName() << "";
  166.             clientfile << inte.getAddress().getTown() << "";
  167.             clientfile << inte.getTelNo().getAreaCode() << "";
  168.             clientfile << inte.getTelNo().getExchange() << "";
  169.             clientfile << inte.getTelNo().getLine() << "";
  170.             clientfile << inte.getAnimal().getBreed() << "";
  171.             clientfile << inte.getAnimal().getType() << "";
  172.             clientfile << inte.getAnimal().getGender() << "";
  173.             clientfile << inte.getAnimal().getAge() << "";
  174.             clientfile << inte.getAnimal().getProblem() << "";
  175.             clientfile << inte.getDate().getDay() << "";
  176.             clientfile << inte.getDate().getMonth() << "";
  177.             clientfile << inte.getDate().getYear() << "";
  178.             clientfile << inte.getTime().getHour() << "";
  179.             clientfile << inte.getTime().getMin() << "";
  180.             clientfile << endl;
  181.             clientfile.close();
  182.         }//end if
  183.  
  184.  
  185.     else{
  186.         cerr << "Intervention #" << interNo << " already contains information. " << endl;
  187.     }
  188. }
  189. //**********************************************************************
  190. Intervention ViewAll(string name, Intervention inte)
  191. {
  192.     ifstream clientfile(name, ios::in);
  193.     if (clientfile)
  194.     {
  195.         int hour, min, day, month, yr, snum, age;
  196.         string fname, lname, interNo, problem, clinic, area, ex, li, type, breed, gender, sname, town, pay;
  197.  
  198.         while (clientfile && !clientfile.eof())
  199.         { //needed to loop through each record in the file
  200.             clientfile >> interNo;
  201.             clientfile >> clinic;
  202.             clientfile >> lname;
  203.             clientfile >> fname;
  204.             clientfile >> pay;
  205.             clientfile >> snum;
  206.             clientfile >> sname;
  207.             clientfile>> town;
  208.             clientfile >> area;
  209.             clientfile >> ex;
  210.             clientfile >> li;
  211.             clientfile >> type;
  212.             clientfile >> breed;
  213.             clientfile >> gender;
  214.             clientfile >> problem;
  215.             clientfile >> age;
  216.             clientfile >> day;
  217.             clientfile >> month;
  218.             clientfile >> yr;
  219.             clientfile >> hour;
  220.             clientfile >> min;
  221.  
  222.             if (fname == inte.getClient().getFname())
  223.             {
  224.                 break;
  225.             }
  226.         }
  227.  
  228.         //after record is found, create record
  229.         inte.getClient();
  230.         inte.display();
  231.         system("pause");
  232.     }
  233.  
  234.     return inte;
  235. }
Nov 2 '13 #1
0 1192

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

Similar topics

2
by: none | last post by:
Hi, Any one know of some code to read cobol data files.... thanks timb
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
2
by: JIM.H. | last post by:
Hello, I need to read all the files in current and sub folders and put it into a list box, is there any example in C# I can use?
7
by: Tracks | last post by:
I have old legacy code from vb5 where data was written to a file with a variant declaration (this was actually a coding error?)... in vb5 the code was: Dim thisdata as integer Dim thatdata...
2
by: asenthil | last post by:
i'm trying to read and write files using java... some errors occurs when i'm trying this code.. Error in java: Cannot find symbol location: class java.io.FileOutputStream FileOutputStream...
1
by: dhingchangs | last post by:
Hi, I want to read a sequential file character by character and the check each character for the position and process further. The lenght of file can be anything. Actually my purpose is read a...
4
by: parveen | last post by:
Can We read client side files using javascript? not only text files
1
by: ajmerasunny | last post by:
Hi All, I have a java web application in which I need to read a configuration file(WebAgent.conf) that has the reference of another configuration file(SmHost.conf). I am placing both these...
5
by: sepgiv | last post by:
I am using OPENDATASOURCE to read data from files when the file extension is txt ,retrieve is successful select * from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 'Data...
1
by: Deltafox777 | last post by:
How to write and read from a sequential file into the game Hangman using fstream? Here are the instructions. Functions enterNewWords() and readFromFile() . Instead of displaying the contents of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.