Hardware: The PCs in the lab for conducting your practical.

computer science

Description

UCCD1004 PROGRAMMING CONCEPTS AND PRACTICES

ASSIGNMENT 1

DUE DATE FOR ASSIGNMENT 1: WEEK 6, FRIDAY BEFORE 5.00PM

 

Please READ and FOLLOW all the INSTRUCTIONS carefully.  You can reuse the code covered in the lectures or from the text book.

1.      EQUIPMENT

Hardware: The PCs in the lab for conducting your practical.

Software: The Microsoft Visual Studio 2017. Your programming will be tested by the markers using Visual Studio 2017.

2.      PROJECT:

This is an INDIVIDUAL assignment. NO help should be obtained from any other persons, as well as the Internet.

3.      DESCRIPTION OF PROJECT:

The assignment focuses on some important aspects of structured programming practices. The aim of this assignment is to provide an opportunity to demonstrate that you have acquired the skills and ability to be proficient in the area of developing C++ application program using modular approach.

4.      ACADEMIC HONESTY AND COLLABORATION

Cooperation is recommended ONLY in understanding various concepts and system features. However, the actual solution of the assignment, the programming and debugging must be your individual work, except for what you specifically credit to other sources. (Your grade will be based on your own contribution.) For example, copying without attribution any part of someone’s program is plagiarism, even if you modify it and even if the source is a textbook. You can document the credit to other sources at the start of your program code listing. Offenders will be awarded with zero mark for this assignment.

5.      PENALTY

Penalties such as downgrade or reduction of marks will be given to empty or late submissions unless legitimate reasons are provided.

 

 

 

A.    Objective

Write a C++ program to output the value of  WITHOUT using any library functions other than iostream, when the input is a positive real number.  You MUST use (or follow) the pseudocode given in Section C.

 

 

B.     The Background Theory

Notation: For any real numbers  and, where ,  is the set of real numbers which are greater than , and less than .

 

Fact 1: For any positive real number, (1) if, then; (2) if, then; (3) if, then

 

Observations: If , just need to output 1.  Else,  is sandwiched by and , no matter whether  or .  So, we search  if , and  if .

 

Fact 2: For , suppose that  is located inside , for some real numbers , where .  Let the middle point of  be , and .  There are three cases:  (1) if , then  is located inside ;  (2) if , then  is located inside ;  and (3) if , then .

 

Observations: When we know that  is located in , we compare  and .  If , then we are lucky, and can claim .  If , then the possible range of  will be narrowed down to either  or , and the widths of both intervals are half of the original one .  We now can focus on either  or .  After repeating the same steps, the width of the interval concerned will be further halved.  This is the basic idea of the whole assignment.  For your interest, in the literature, this technique is called bisection method.


Related Questions in computer science category