[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

program with arrays: y=ln(x)

Posted on 2006-04-24
7
Medium Priority
?
340 Views
Last Modified: 2010-04-16
Hey,
 Wondered if anyone might have any idea how to do this program, been giving me a bit of hassle. Thanks a million!
 
 y=loge(x), i need to write a program which will display a table of logs for varying values of x. Theuser should be instructed to enter the minimum value of x, the maximum value and the size of increment between these values. The program should then use one procedure to calculate thevalues of x and store them in an array and another procedure to calculate the corresponding values of y (also in an array).
e.g.. the user has entered xmin = 0.1, xmax = 1.0, xincrement = 0.05
The x array will therefore have the values :
0.10, 0.15, 0.20, …. Which will fill the x array.
And the y array will therefore have the values :
-2,30, -1.89, -1.61, …. Which will fill the y array.
You will have to make sure the user can't ask for more points than are contained in the array.
For example, if you define your arrays to have 50 elements and the user needs 100 points
between xmin and xmax then you must stop and warn the user that they have asked for too many
points and ask them to try again..
0
Comment
Question by:eimearneeson
5 Comments
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16532769
Hi,
This looks like a homework so you have to post the code of what you've done so far and we can help you then if there are some mistakes.
0
 

Author Comment

by:eimearneeson
ID: 16548744
yeah, so far

PROGRAM ln_example;

VAR
  list     : ARRAY [0..100] OF integer;
  loge   : ARRAY[ARRAY[0..10] OF integer OF O..100;
  num   : integer;
  inc     : integer;
  numz : integer;

BEGIN

   begin
      num := num + inc;
      IF num > 0 AND num <= numz DO
      list (ARRAY[num]);
  end;

   begin
     loge  := ln(lit(num));
   end;

   writeln('Please enter minimum x value: ':2);
   readln(num);
   writeln('Please enter maximum x value: ':2);
   readln(numz);
   writeln('Please enter size of increment: ':2);
   readln(inc);
   writeln(loge[num]);

END.

if you could point out what ive done wrong, that would be amazing. thanks.
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16548783
loge   : ARRAY[ARRAY[0..10] OF integer OF O..100;
what is the idea of this one?
what is ARRAY[ARRAY
also in O..100 I suppose it has to be 0 (zero) not O (the letter O)
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 252 total points
ID: 16549645
YOu will want to use parallel arrays.  By that I mean the arrays have the same shape and indices.

Since your list is 1 - 100 then your array for the loge must also be 1 - 100.  Same basic declaration.

Have you learned about user defined data types?  Have you learned about functions and procedures?

THink about how you would do this manually

Step 1 - Ask user how many values, minimum value, and increment
Step 2 - Validate values - what values for each would be invalid - (More than your program allows, negative minimum value, etc)
     Repat step 1 & 2 for each invalid value
Step 3 -

mlmcc
0
 
LVL 10

Assisted Solution

by:For-Soft
For-Soft earned 248 total points
ID: 16571262
VAR
  list     : ARRAY [0..100] OF integer;
  loge   : ARRAY[ARRAY[0..10] OF integer OF O..100;
  num   : integer;
  inc     : integer;
  numz : integer;

As an example you used real type values. It is not possible to store such values in variables you declared. The variables have to be real type to work correctly in such a case:

const SizeOfArray = 100;

VAR
  list     : ARRAY [0..SizeOfArray] OF Real;
  loge   : ARRAY [0..SizeOfArray] OF Real;
  num   : Real;
  inc     : Real;
  numz : Real;

The SizeOfArray constant is just to make changing of the array size more easy. But it shows the both arrays have to be the same size. It is possible to declare 1 variable instead of two. But, you told us you have to create two separate tables. So, I'll leave it, for now.

The rest of your program should follow the steps, just like Mlmcc said. The validation of the values should be done in some sort of a loop. Repeat .. Until is a possible solution:

BEGIN

 repeat
 
 {STEP 1 - Ask user how many values, minimum value, and increment}
   writeln('Please enter minimum x value: ':2);
   readln(num);
   writeln('Please enter maximum x value: ':2);
   readln(numz);
   writeln('Please enter size of increment: ':2);
   readln(inc);
   writeln(loge[num]);

 {Step 2 - Validate values}
 until (validation expression goes here)

 {Step 3 - }

END.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

834 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