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 salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
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 Specifications: Write a program that defines a class HumanBMI, implements it as required, and tests...
Program Specifications: Write a program that defines a class HumanBMI, implements it as required, and tests the class implementation. The class definition and implementation should be separated into HumanBMI.h and HumanBMI.cpp files. A. The class HumanBMI consists of three private member variables: name of type string, height of type int in inches, and weight of type int in pounds. The class HumanBMI also includes the following public member functions: 1) setName to set the name member variable with a string...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT