Solved

create two separate files and print

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to send email in delphi with image 4 588
ROUND() from fbudf.dll only gives integers 2 1,052
searching for DavidI's "Mobile Summer School download" 3 132
Newbie Thread Programming 1 152
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Google always has something new and amazing up its sleeve, and the most current thing that they have been working on is another step in the evolution of Google Search, from machine learning to its brilliant successor, deep learning.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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