Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

create two separate files and print

Posted on 2000-02-28
2
Medium Priority
?
178 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
2 Comments
 
LVL 50

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview

971 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