Starting from:
$30

$24

Assignment 6 Solution

Preparation




Read Lesson 5



Read text ch 5



For Credit




Assignment 6.1 [35 points]




Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done, report to the user the position of the first 7 entered and the last 7 entered. By position we mean, for example, that if the first 7 is the 2nd number entered then its position would be 2. Turn in the following 3 outputs exactly as you see them below to demonstrate that your program works in each case.




Don't forget to use a named constant for the "7".




Sample screen output 1:




How many numbers will be entered? 8

Enter num:
5
Enter num:
7
Enter num:
6
Enter num:
7
Enter num:
7
Enter num:
3
Enter num:
8
Enter num:
6
The first 7 was in position 2
The last 7
was in position 5
Sample screen output 2:
How many numbers will be entered? 8
Enter num:
5
Enter num:
2
Enter num:
6
Enter num:
7
Enter num:
1
Enter num:
3
Enter num:
8
Enter num:
6
The first 7 was in position 4
The last 7
was in position 4



Sample screen output 3:




How many numbers will be entered? 8

Enter num: 5

Enter num: 1

Enter num: 6

Enter num: 5

Enter num: 9

Enter num: 3

Enter num: 8

Enter num: 6

Sorry, no 7's were entered.




Turn in your source code followed by 3 outputs, one that matches each of the three sample screen outputs given above.




Assignment 6.2 [35 points]



Write a program that inputs an integer greater than 0 and calculates the sum of the squares of the numbers from 1 to that integer. For example, if the integer equals 4, the sum of the squares is 30 (1 + 4 + 9 + 16). The program should repeat this process until the user wants to quit. An input value less than or equal to 0 signals the end of the data. Note: there is a formula that you could use to calculate the sum of the squares with a single assignment statement, without using a loop. You must write this program without using that formula.




Sample screen output:




Enter a number greater than 0 (less than 1 to quit): 4

The sum of the squares from 1 to 4 is 30

Enter a number greater than 0 (less than 1 to quit): 1

The sum of the squares from 1 to 1 is 1




Enter a number greater than 0 (less than 1 to quit): 0




Turn in your source code and one output exactly like the sample given above.




Submit Your Work




Execute each program and copy/paste the output into the bottom of the corresponding source code file, making it into a comment. Send an email to ta.sanmateo@gmail.com with the subject "CIS 254 a6". Attach your source code file(s) to the email. In the body of the email let me know whether the programs work as required.




Keep in mind that if your code does not compile you will receive a 0.




Note that the gmail email account is for homework submission only. The account is not monitored for any other purpose.




Assignment 6.3 [5 points]




Participate in the lesson 6 discussion. This could involve asking a question, answering another student's question, giving an example of something that you struggled with and then overcame (or didn't!), giving an example of something you found particularly cool, or any other constructive way you can think of to participate.

More products