Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sultan Qaboos University College of Science-Department of Computer Science COMP2101: Introduction to Computer Science-Spring 2017 Homework Assignment 3 Due date: Sunday 2 April 2011. 23:55pmeon

image text in transcribed
Sultan Qaboos University College of Science-Department of Computer Science COMP2101: Introduction to Computer Science-Spring 2017 Homework Assignment 3 Due date: Sunday 2 April 2011. 23:55pmeon Moodle) Submit also a hard copy of your cpp tile including an algorithm and a test plan as comments at the beginning of the program by Monday 34/2017. The ccmath function sqrtb) is used to calculate the exact square-root value of the number r such thatx is a non-negative real number. The square root value of can also be estimated using the folowing mathematical equation: e 2.718282, and lnis the naturallogarithm; called log in Write a C++ program that calculates and writes to an output fle the exact and estimated square roots of a list of numbers. The list of numbers is either read from the keyboard, generated randomlyor read from an input file. The program displays to the user the following menu and performs the corresponding tasks based on the user's selection. The program should keep running until the user enters Q or q. K: Read the list of numbers from the keyboard R: Generate the list ofnumbers randomly F: Read the list of numbers from an input file Q: Quit the program If the user enters K' or the program should read a list of numbers terminated by Ctrl+z from the if the user enters R or Y the program should ask the userto specify how manynumbers to generate randomly and then generates that many random values. The generated numbers MUST range between 5.000 and 20.000. For this purpose use the rand0 function to return values between 5000 and 20000 and divide them by 1000. Hthe user enters F or f, the program should read the list of numbers from an input file which could be empty or contain any number of values given individualyon separate ines. The name of the input file is For each of the 3 menu options K Rand F, the program should calculate the exact and estimated square roots of the obtained list of numbers and write the results in an output file called 'square roots tot'. The program should ignore Eskiplany negative values inthe ist of numbers and do the calculations and display the results only forthenonnegative values. The output should be written to the output file in tabular format including for each non-negative number x in the list, the number xitself its exact root its estimated root, and the absolute value of the difference between the two roots. Format the a's with 3 digits after the decimal point and format the roots and the difference between them with 6digits after the decimal point

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

McDonald's 2019 return on common equity=?

Answered: 1 week ago

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago