A3

.pdf

School

Arizona State University *

*We aren’t endorsed by this school

Course

100

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

5

Uploaded by ChefClover20268

Report
Assignment 3 - Due on Feb. 24 CSE 100 - Assighment 3 No late assignment will be accepted. Maximum Points: 20 pts Due Date: February 24 by 11:59PM Topics: Chapters 4 & 5 o Control Flow -- Conditional and repetition (loop) statements Your programming assignments require individual work and effort to be of any benefit. Every student must work independently on his or her assignments. You must work alone on the assignments no collaboration of any kind is permitted. You cannot use Google, StackOverflow, Chegg or any other on-line resources to look up for the solution. Sharing your assignments with others in any way is NOT permitted. Violations of the University Academic Integrity policy will not be ignored. Violations of the University Academic Integrity policy will not be ignored. The university academic integrity policy is found at Important Note: All submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit. [ // AUTHOR: your name // FILENAME: title of the source file I/ SPECIFICATION: description of the program // FOR: CSE 100- homework #- days and time of your class // TIME SPENT: how long it took you to complete the assignment /] */
Reasonably good amount of comments should be added in your program so tr people to understand it. Please see the comment style in the textbook. Part 1: Written Exercises: (4 points) What do the following loops print? Work out the answers by tracing the code, r computer. a. int s = 1; int n; for (n=1; n<=4; n++) { S += n; N++; } cout << s << << n; double x double y int i= o do { } while (x < 1.8); cout << "Value of 1 is: " << 1i; string stars = "¥xx¥*". string strips = "====="; int i = @; while ( i< 10) { if (i%2 ==0) cout<< stars << endl; else cout << strips << endl; i++; } d. for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) if (j==k) cout << "$" ; else cout << "*" << "\n" ; Write a C++ program called Assighment3.cpp. There are two tasks in this ast program will ask for user to choose task 1 or task 2 and based on which it will two tasks. (use switch for the 2 tasks)
After performing the selected task, your program should ask the user if t| another execution of the program. If the user chooses to continue, then y loop again and display the option for the two tasks, else it should termin: Read the instructions carefully for each task. Follow the instruction step by ste next step if your program does not return the proper output from previous step. Task 1: Ask user to enter two integers, then compute, and print the greatest common ¢ integers. For instance, given integers 24 and 18, the greatest common divisor is 6, beca integer that divides evenly into both 24 and 18. We will denote the greatest co y as gcd(x, y). The algorithm is based on the clever idea that the gcd(x, y) = g The algorithm consists of a series of steps (loop iterations) where the “larger” i the difference of the larger and smaller integer. In the example below, we compute gcd(72, 54) and list each loop iteration comr line. The whole process stops when one of the integers becomes zero. When greatest common divisor is the non-zero integer. gcd(72, 54) gcd(18, 54) gcd(18, 36) gcd(18, 18) gcd(72 - 54, 54) gcd(18, 54 - 18) gcd(18, 36 - 18) gcd(18 - 18, 18) gcd(18, 54) gcd(18, 36) gcd(18, 18) gcd(0, 18) = 18 To summarize: Create a loop, and subtract the smaller integer from the larger one (if the in may choose either one as the “larger”) during each iteration. Replace the larger integer with the computed difference. Continue looping until one of the integers becomes zero. Print out the non-zero integer. Task 2- Read in a sequence of positive integers until a user enters -1 to quit (we don't | numbers the user may enter). The loop continues to process input values until Below is sample of the program execution. Once user enters -1, then stop aski integers, and compute the largest, smallest among the integers, the number of by the user, the number of odd integers entered by the user, and the cumulativ entered by the user. DO NOT include -1 in the computation which is the last in program.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help