Question

In: Computer Science

** Pascal ** Write a simple program in Pascal with these specifications: 1. Calculates real root...

** Pascal ** Write a simple program in Pascal with these specifications:

1. Calculates real root of number entered by user (if root happens to be a complex number, print message "The root is complex").

2. The program keeps asking for input, user can input a key to terminate program. (e.g: Press 1 to enter calculator, Press any other key to exit calculator).

Solutions

Expert Solution

Program with comments to explain each step:

Program RealRootCalculator; {Name of Program}
var choice: integer; {declaring an integer type variable to store choice to enter and exit the program}
var number: real; {root of this variable will be calculated}
begin
writeln('Press 1 to enter into the real root calculator');
read(choice);
writeln('Choice = ', choice);
if choice =1 then {if user enters 1, program will enable user to calculate real roots else exit}
begin
writeln('Welcome to real root calculator');
repeat {program keep on calculating roots untill choice is 1}
writeln('Enter the number : ');
read(number);
if number < 1 then writeln('Imaginary roots') {when -ve number is entered, program will print imaginary roots}
else writeln('Root of', number:0:2,' :', sqrt(number):0:2);

writeln('Enter 1 to continue or any other key to exit');
read(choice);
until choice <> 1 {loop will be terminated when this condition, choice not equal to 1 becomes true, if user keep entering 1 then program keeps running and will not exit}
end;
writeln('exited from calculator');
end.

=========================

Output

==========================

Press 1 to enter into the real root calculator : 1
Welcome to real root calculator
Enter the number : 3
Root of 3.00 :1.73
Enter 1 to continue or any other key to exit : 1
Enter the number : 
Root of 5.00 :2.24
Enter 1 to continue or any other key to exit : 1
Enter the number : -5
Imaginary roots
Enter 1 to continue or any other key to exit : 5
exited from calculator

Related Solutions

Write a Java program that calculates a random number 1 through 100. The program then asks...
Write a Java program that calculates a random number 1 through 100. The program then asks the user to guess the number.If the user guesses too high or too low then the program should output "too high" or "too low" accordingly.The program must let the user continue to guess until the user correctly guesses the number. ★Modify the program to output how many guesses it took the user to correctly guess the right number
Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Write a program that calculates the balance of a savings account at the end of a...
Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following: Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the balance. Ask the user for the...
Write a program that calculates the balance of a savings account at the end of a...
Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, performing the following: Ask the user for the amount deposited into the account during the month. (Do not accept negative numbers.) This amount should be added...
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
Write a multithreaded program that calculates various statistical values for a list of numbers. This program...
Write a multithreaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 81 78 95 79 72 85 The program will report The...
Write a program that calculates the mean, median and mode of a given array in the...
Write a program that calculates the mean, median and mode of a given array in the following manner: i) Write three functions mean (), median () and mode () that calculates the mean, median and mode of an array. ii) Using these functions write a program that calculates all the three above mentioned values for two different arrays A and B where A is an array that contains the number of hours spent by a person each day for playing...
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT