Solved

create two separate files and print

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now