1. a) Write a program using a for loop that inputs (x,y) coordinates for 3 points...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. a) Write a program using a for loop that inputs (x,y) coordinates for 3 points from the keyboard (with cin) using 1D arrays of doubles for x and y. It also inputs 3 colour components r, g, and b using doubles. b) Declare variables to be used as arguments for the triangle(...) 2D graphics function and initialize them to the results from part a). The program then prints the arguments to the screen using cout. Check the arguments for a variety of keyboard inputs. Note it is assumed that the colour coordinate of each (x,y) point is the same value given by r, g, and b. c) Call the triangle(...) function with the results of part b). Verify that a triangle is drawn in the DirectX graphics window depending on the keyboard input. d) Using if statements check if the values of r, g, and b are out of range before the triangle(...) function is called from part c). If they are out of range then set their value to the closest valid number. For example, if the input for r is 3 then r is set equal to 1. If the input for g is -1 then g is set equal to 0. Why isn't it necessary to check if the (x,y) coordinates are out of range? What happens in that case? Try it and see what happens. Check your solutions for a) to d) with a variety of different keyboard inputs. 2. Write a program that plots the function y=sin(x) over the range x = 0 to x = 2*Pl using the following steps. a) Program a for loop to calculate 1D arrays of doubles x[100], y[100] where n = 100; delta_x = 2*PI / (n-1); // n points give n-1 divisions of size delta_x x[i] = delta_x * i; y[i] = sin( x[i]); where i goes from i = 0 up to and including i = n-1 b) Using the information from part a), declare and initialize appropriate function arguments for the line(...) 2D graphics function (use green colour). Then print out the arguments to the screen using cout. The arrays x[i] and y[i] first need to be scaled and translated to screen coordinates xs[i], ys[i] before drawing the line, so they are the right size and position on the screen. This can be achieved using the following equations with a for loop. double x_scale = 600, y_scale = 200; double x0_plot = 100, y0_plot = 300; xs[i] = x[i]/(2*PI) * x_scale + x0_plot; ys[i] = y[i] *y_scale + y0_plot; Apply the equations above to the results of part a) and print out the array elements to the screen using cout to check them. 1. a) Write a program using a for loop that inputs (x,y) coordinates for 3 points from the keyboard (with cin) using 1D arrays of doubles for x and y. It also inputs 3 colour components r, g, and b using doubles. b) Declare variables to be used as arguments for the triangle(...) 2D graphics function and initialize them to the results from part a). The program then prints the arguments to the screen using cout. Check the arguments for a variety of keyboard inputs. Note it is assumed that the colour coordinate of each (x,y) point is the same value given by r, g, and b. c) Call the triangle(...) function with the results of part b). Verify that a triangle is drawn in the DirectX graphics window depending on the keyboard input. d) Using if statements check if the values of r, g, and b are out of range before the triangle(...) function is called from part c). If they are out of range then set their value to the closest valid number. For example, if the input for r is 3 then r is set equal to 1. If the input for g is -1 then g is set equal to 0. Why isn't it necessary to check if the (x,y) coordinates are out of range? What happens in that case? Try it and see what happens. Check your solutions for a) to d) with a variety of different keyboard inputs. 2. Write a program that plots the function y=sin(x) over the range x = 0 to x = 2*Pl using the following steps. a) Program a for loop to calculate 1D arrays of doubles x[100], y[100] where n = 100; delta_x = 2*PI / (n-1); // n points give n-1 divisions of size delta_x x[i] = delta_x * i; y[i] = sin( x[i]); where i goes from i = 0 up to and including i = n-1 b) Using the information from part a), declare and initialize appropriate function arguments for the line(...) 2D graphics function (use green colour). Then print out the arguments to the screen using cout. The arrays x[i] and y[i] first need to be scaled and translated to screen coordinates xs[i], ys[i] before drawing the line, so they are the right size and position on the screen. This can be achieved using the following equations with a for loop. double x_scale = 600, y_scale = 200; double x0_plot = 100, y0_plot = 300; xs[i] = x[i]/(2*PI) * x_scale + x0_plot; ys[i] = y[i] *y_scale + y0_plot; Apply the equations above to the results of part a) and print out the array elements to the screen using cout to check them.
Expert Answer:
Answer rating: 100% (QA)
It seems like youre combining two different programming tasks one involving DirectX graphics and ano... View the full answer
Related Book For
McGraw-Hill Education SAT 2017
ISBN: 9781259641657
1st Edition
Authors: Christopher Black, Mark Anestis
Posted Date:
Students also viewed these programming questions
-
A 0.800 kg hammer is moving horizontally at 6.00 m/s when it strikes a nail and comes to rest after driving it 1.00 cm into a board. (a) Calculate the duration of the impact in seconds. (Enter a...
-
Describe the process and challenges of database migration. Discuss the steps involved in migrating a database from one platform to another, including data mapping, transformation, and validation....
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
John Black is considering to purchasing a land from Real Estate Ltd for $1,000,000. The terms of the agreement are, 10% down payment, and the balance is to be repaid at 20% interest for duration of...
-
Was the project revision the main problem for this group? If not, what was?
-
Assume inflation is 0.2% per month. Would you rather earn a nominal return of 0.75% per month, or a real return of 6.5% APR, compounded annually?
-
What set of eco-efficiency characteristics is the shareholder value approach concerned with identifying?
-
State Senator Bowdler convinced the legislature of State Z to pass a law requiring all professors to submit their class notes and transparencies to a board of censors to be sure that no lewd...
-
Define what "opportunity cost" is. Discuss what the opportunity cost of attending college is for you, noting that the concepts of opportunity (implicit, indirect) cost and explicit monetary cost are...
-
The 450-room Hotel Fernando is a four-star full-service hotel in San Petresco. It is highly regarded among both locals and tourists. Its service standards and ameni- ties complement its exquisite...
-
The column is made of wood. It is fixed at its bot- tom and free at its top. Use the NFPA formulas to determine the largest allowable axial load P that it can support if it has a length L = 1.2m. 50...
-
3. Depreciation on non-current assets is as follows: Vehicles: 20% on the fixed line method Buildings: 30% on the straight line method Machines: 25% on the diminishing balance method Land is not...
-
you purchased a new washer and dryer for $123.999including salestax and delivery). Financing was used for the fullpurchase price and the payments are $144.84 per month for 11months. what is the cost...
-
3. Consider a market for bottled water served by only two firms, Aquapura and Mountain Spring. Each firm can draw water free of charge from a mineral spring located on its own land. Customers supply...
-
Beta Ltd is a diversified entity whose reporting date is 31 December. The entity uses the perpetual inventory system and the following information, relating to the acquisition of trading inventory,...
-
Ameer invested $ 926 in a bank account that earns 12.98 percent per year. How much will Ameer receive after 14.12 years of maintaining the investment the account? Do NOT include $ in your answer....
-
Factor each of the following quadratic polynomials using the shortcuts you developed previously. Part A: x + 10x + 24 Answer: Part B: x + 5x - 6 Answer: Part C: 14 Answer: 9x + x Part D: 4x + 2x - 3x...
-
Reichenbach Co., organized in 2018, has set up a single account for all intangible assets. The following summary discloses the debit entries that have been recorded during 2018 and 2019. Instructions...
-
If |x + 4| = |x 5|, what is the value of x?
-
The author regards the examples listed in lines 57 as A) Scientific frauds B) Astonishing discoveries C) Faulty conclusions D) Quaint traditions
-
Rewrite each underlined portion, if necessary, to correct any dangling or misplaced modifiers. Determined to avenge his friend, the sword was unsheathed by Claudius.
-
What are the advantages of resource leveling?
-
Which of the following statements is false? A. The highest need in Maslows pyramid is called selfactualization. B. Most people today prefer managers who follow Theory X versus Theory Y. C. Herzberg...
-
Some project managers like to assess team performance by using a technique known as MBWA, which stands for _______________. A. management by wondering aloud B. management by wandering around C....
Study smarter with the SolutionInn App