AllExperts > Experts 
Search      

Pascal

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Pascal Answers
Question Library

Ask a question about Pascal
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About J_Pooria
Expertise
I`m a retired Pascal Programmer! I can answer most questions about regular and specially system programming. I can help with computer mathematics and algorithms, runtime bugs and program troubleshooting, system programming, TSR programs, Graphics, Data Structures, Data Types, and of course questions about files, structured programming, basics of Pascal, etc... . I can also help about "Turbo Pascal" and "Borland Pascal". My major experience is in dos, so I can`t answer platform-dependent or compiler-dependent questions about Linux, UNIX, Mac, etc and their compilers.

Experience
System Programming (Under DOS)
Graphics (Under DOS)
Computer Mathematics and Algorithms
Program Debugging and Troubleshooting
Turbo Pascal
Borland Pascal
Files
Structured Programming
Data Structures
Data Types
Program Structure


 
   

You are here:  Experts > Computing/Technology > Pascal > Pascal > Pascal Matching Problem (Recs n Files)

Topic: Pascal



Expert: J_Pooria
Date: 3/20/2005
Subject: Pascal Matching Problem (Recs n Files)

Question
Thank You J_Pooria, that was helpful, and i am grateful. I jus need to ask one more question on validation. For cust_name which is declared a string, i want the program to be able to check to see if there are any numbers within it, and display an error message if there is.

Also for order_date which is set as a string[8] i need this to be checked to make sure it is in a certain format. The date needs to be in format 12/12/05. I want the program to check if the forward slashes are present and are in the right place, and that the day section doesn't go past 23, the month section can only be 12 and the year can be no less than 05. Thank You.
-------------------------
Followup To
Question -
Hi, I have been set the task at my college to create a program for an ordering system in Turbo Pascal V7. I have an orders file and a turkey file. The order file is record structured with the fields: customer name * order ID * date of order * no. of turkey requested * weight of each turkey requested. The turkey file is record structured and includes the fields Turkey ID and Turkey Weight. There are 40 turkeys in this turkey file, and 12 customer orders in the orders file. Now i am stuck on how to match customers requests to turkeys. I want it so that the user can match customer requests to turkeys himself. (For example, the user can match customer no.2 with turkeys 3 and 7. How would I save these matches to a file as well? How would i use these matches to create a customer bill, (for example it is £4.78 for one kilogram of turkey, if a customer had two 6 kilogram turkeys on the match file, how would i retrieve that info and calculate the bill and output it on screen? Thank You J_Pooria, I hope I have been clear, I have trouble explaining things.
Answer -
Hi dear Paul Wilcock,

Sorry for answering late, since I was stuck in some work and couldn't check your question.

I just couldn't understand from you question :
Does the user have to match turkeys with customers or your program has to do it?

If the user has to do the matching, you may just define a structure with fields : customer-id & an array of turkey-ids and save it in the file.

If your program has to match the turkeys with the customers,
you may read all the turkey data and store them in an array and then start scanning the customers' information and scan the array of turkeys data to find the matching turkey.
for example if the array of turkeys data is Turkey:
The algorithm will bw something like what you see below:

{
for i:=1 to 12 do
begin
{x=number of left turkeys;}
n= number of the ith customer's orders;
for j:=1 to n do
begin
m=the wight of nth turkey ordered{in the customer data};
for k:=1 to x do
begin
if Turkey[k].weight = m then
begin
    match turkey ordered no.j with turkey no.k
    decrease x;{one turkey has gone,no of left turkeys is decreased}
end;
end;

end;
end;

}

so for calculation , you only need to read the new array of customers(customer-id & an array of turkey-ids) and multiply
the some of wights of turkeys in a customers record by the price of unti and return it as total cost.

I hope I could say my idea clearly,since I have a liitle problem in conveying meaning in English(!).

Anyway I'm ready to answer you If you had any problem understanding the answer(or if I had any misunderstanding about your question(!)).

Good luck.
J_Pooria

Answer
Hello dear Paul Wilcock,

About the cust_name string, you may easily check it in a for loop.For example :

Flag:=false;{Flag : Boolean}
F:=Length(cust_name);{F is defined as an Integer}
for i:=1 to F do
begin
 case cust_name[i] of
   '0'..'9':Flag:=ture;
 end;
end;

The if flag=true it means that there is a number character in the string ,otherwise there isn't.

You can do the same to access the elements of order_date, for example order_date[3] should be equal to '/' or order_date[4] shoulde be between '0'..'1',and so on.

I hope you a successful project.

Good Luck,
J_Pooria.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.