Solved

create two separate files and print

Posted on 2000-02-28
2
171 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 48

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 20 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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