?
Solved

create two separate files and print

Posted on 2000-02-28
2
Medium Priority
?
177 Views
Last Modified: 2010-04-16
Each data group for the file customer.dat contains a customer's name, address, gender, and balance due. I need a program that will create two separate files, male.dat and female.dat, with all the data for customers stored on the appropiate file. It will also have to print out the following:
total number of customers, number of males, number of females, average balance for males, and average balance for females.

Can I use the code in my other question? http://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10302610 
0
Comment
Question by:kazooie21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 49

Expert Comment

by:dbrunton
ID: 2567822
Yes.

The basics are there.  Roughly

females := 0;
males := 0;
malebalance := 0;
femalebalance := 0;

while not eof(customerfile)
  readln(customerfile, name);
  readln(customerfile, address);
  readln(customerfile, gender);
  readln(customerfile, balance);
  if gender = 'M' then
    begin
      write(malefile, name);
      write(malefile, address);
 etc
      malebalance := malebalance + balance;
      inc(males);
    end
  else
    begin
      write(femalefile, name);
etc
      femalebalance := femalebalance + balance
      inc(females);
    end;


you should be able to finish this off by calculating total number of customers and mean average balances.
0
 
LVL 3

Accepted Solution

by:
sumant032199 earned 80 total points
ID: 2569955
{ I can give you brief outline of program. }
program malefemale;
uses crt;

type customer = record
       name : as a string;
       address : as a string;
       gender : char;
       balance : real;
    end;
    IOFiles = file of customer;

var male,female,reading : IOFiles;
    cust1 : customer;
    TotalMale, TotalFemale, Total : integer;
    AddMale,AddFemale : real;

procedure generate_database;
var    c : char;
begin
    repeat
       { Take each value and store it in cust1.<data field>
        then into file }
       write(reading,cust1);

       write('Do you want to enter more (Y/N)? ');
       { continue till user enters 'N' to above question }

    until c = 'N';

end;
procedure sort_database;
begin
     while not eof(reading) do
     begin
          { reading file is done inthe way }
          read(reading,cust1);
          Total := Total + 1;

          { check gender using if statement }
          if  then
          begin
                { Write to male file and then increment the numbers.}
          end
          else
          begin
                { Write to female file and then increment the numbers.}
          end;
      end;
end;
begin
     clrscr;
{ assign statement is required in Turbo Pascal in following way. }
     assign(reading,'CUSTOMER.DAT');
     assign(male,'MALE.DAT');
     assign(female,'FEMALE.DAT');
{ use correct routine to openfile for reading and writing. }
     re....(reading);
     re....(male);
     re....(female);

     {If you are running for the first time then }
     {generate_database;}
     sort_database;
     writeln;
     writeln('Total Customers    = ',Total:8);
     writeln('Total Males        = ',TotalMale:8);
     writeln('Total Females      = ',TotalFemale:8);

     if Totalmale = 0 then writeln('Average of males   = 0.0')
     else writeln('Average of Males   = ',(Addmale / Totalmale):8:2);
     if TotalFemale = 0 then  writeln('Average of females = 0.0')
     else writeln('Average of Females = ',(AddFemale / TotalFemale):8:2);
{ don't forget to close each open file }

end.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question