1. Homepage
  2. Programming
  3. CS 159: C Programming Lab #8 - Programming Assignment: Loop Control and Integer

CS 159: C Programming Lab #8 - Programming Assignment: Loop Control and Integer

Engage in a Conversation
USPurduePurdue UniversityCS 159CS159C ProgrammingInteger

Solve the following problems related to material found in Chapter 6 and the course standards. CourseNana.COM

Statement CourseNana.COM

The contents of a loop have been identified to be repeated in a program. CourseNana.COM

An iteration is one execution of all statements found inside the body of a loop. CourseNana.COM

The initialization of the loop control variable must take place outside the body of a pretest loop. CourseNana.COM

The condition that determines whether the task to repeat is finished is known as the loop control expression. CourseNana.COM

In a pretest loop the control expression is evaluated before each iteration, including the first iteration. CourseNana.COM

In a post-test loop the minimum number of times that the statements found inside of the loop are executed is one. CourseNana.COM

The action that is responsible for changing the result of the loop control expression from true to false is the loop update. CourseNana.COM

The loop control variable is commonly a part of the loop control expression and the recipient of the loop update action. CourseNana.COM

In an event-controlled loop we know the number of times that the actions found inside the body of the loop will be executed. CourseNana.COM

A counter-controlled loop may execute a constant number of iterations. CourseNana.COM

It is possible for the number of times a counter-controlled loop will iterate to depend on the value of a single variable or expression. CourseNana.COM

The number of times that the loop control expression is evaluated is one more than the number of iterations in a pretest loop. CourseNana.COM

The while loop requires the use of parentheses around the loop control expression. CourseNana.COM

The do-while loop will terminate with a semicolon after its loop control expression. CourseNana.COM

Similar to their required use in the if construct it is a course standard to always make use of { and } with all looping constructs. CourseNana.COM

A limited amount of control structures are permissible in the main function to ensure that it is the main function which makes most of the function calls for a program. CourseNana.COM

A nested loop is a repetitive process contained inside of another repetitive process. CourseNana.COM

One approach to potentially make solving problems that require nested loops easier is to separate each repetitive process into its own function. CourseNana.COM

In order for two, or more, repetitive processes to be considered nested they must appear in the same user- defined function. CourseNana.COM

Input validation is an example of an event-controlled problem. CourseNana.COM

Selection by itself is insufficient for input validation because it provides only a finite number of opportunities for the user to input valid data. CourseNana.COM

In this course you will be expected to validate for the input of both the range of acceptable values and the correct data type. CourseNana.COM

It is expected for many cases that the code for the validation of input be found in the same function that contains the prompt for input and scanf statement. CourseNana.COM

The short-circuit method of evaluating logical expressions does not apply to loop control expressions. CourseNana.COM

Control-forcing statements such as break, continue, exit, and the use of multiple return statements in a user-defined function are prohibited by course standards as mechanisms to terminate repetitive processes. CourseNana.COM

Complete the following table from page 309 of the C programming text (Table 6-1): CourseNana.COM

Pretest Loop CourseNana.COM

Post-test Loop CourseNana.COM

# of times loop control expression is evaluated CourseNana.COM

# of times loop control expression is evaluated CourseNana.COM

# of times the loop iterates CourseNana.COM

# of times the loop iterates CourseNana.COM

Minimum # of times loop is iterated CourseNana.COM

Minimum # of times loop is iterated CourseNana.COM

Use the table below to trace the execution of the loop provided: CourseNana.COM

int x = 3415263; int ct = 0; CourseNana.COM

while(x > 0) CourseNana.COM

{
if(x % 2 == 0)
CourseNana.COM

{ ct++; CourseNana.COM

} CourseNana.COM

x = x / 10; } CourseNana.COM

End of Iteration # CourseNana.COM

Value of X CourseNana.COM

Value of CT CourseNana.COM

1 CourseNana.COM

2 CourseNana.COM

3 CourseNana.COM

4 CourseNana.COM

5 CourseNana.COM

6 CourseNana.COM

7 CourseNana.COM

8 CourseNana.COM

Use the table below to trace the execution of the loop provided: CourseNana.COM

int x = 3415263; int ct = 0; CourseNana.COM

do { CourseNana.COM

x = x / 10; CourseNana.COM

if(x % 2 == 0) { CourseNana.COM

ct++; } CourseNana.COM

}while(x > 0); CourseNana.COM

End of Iteration # CourseNana.COM

Value of X CourseNana.COM

Value of CT CourseNana.COM

1 CourseNana.COM

2 CourseNana.COM

3 CourseNana.COM

4 CourseNana.COM

5 CourseNana.COM

6 CourseNana.COM

7 CourseNana.COM

8 CourseNana.COM

CourseNana.COM

Lab #8 - Programming Assignment
Due:
30 minutes prior to the start of your next lab meeting. 5 Points Possible CourseNana.COM

Collaborative Roles for the Lab Session
Collaborative Teaming. For this lab you will be working in your assigned teams. If you are unable to complete your assignment during the lab then it is expected that your team meet and collaborate outside of class to finish and submit the problem assigned. CourseNana.COM

Role: CourseNana.COM

Description: Every member will rotate roles at every checkpoint. CourseNana.COM

Driver CourseNana.COM

The driver is in charge of the computer which includes entering code, saving, testing, and submitting. This individual should be soliciting the other two members for advice. CourseNana.COM

Navigator CourseNana.COM

The role of the navigator is to look over the shoulder of the driver for syntax errors, logical errors, and concerns related to course standards. Repetitive processes require a control variable, control expression, and update action, the navigator can assist the driver by verifying each has been planned and that the right approach to repetition has been selected. CourseNana.COM

Manager CourseNana.COM

The manager may not be as close to the driver as the navigator but still plays an important role ensuring that the algorithm to be implemented is correct and can be tested using a variety of input to verify correctness. CourseNana.COM

Problem: Given a first (long long) integer (Y) representing the data to analyze and alter in this program, then a second integer (X) corresponding to the size of a number to extract from the first integer Y, identify the largest value in Y composed of X consecutive and adjacent digits. Divide this largest value by two, round it to the nearest whole number, and replace it into the number Y. CourseNana.COM

Your program will need to validate that the first integer is positive and the second integer is both positive and not greater than the number of digits in the first input. CourseNana.COM

Example Execution #1: CourseNana.COM

Enter a positive integer value -> 246895731 Enter desired number of digits -> 2 CourseNana.COM

Max value identified: 95 CourseNana.COM

Updated original value: 246848731 CourseNana.COM

Example Execution #1 Explained: CourseNana.COM

The largest two digit sequence in this number is 95. Divide by two and the result is 47.5, round to 48 and replace the 95 in the original number. CourseNana.COM

Example Execution #2: CourseNana.COM

Enter a positive integer value -> 10101010101 Enter desired number of digits -> 3 CourseNana.COM

Max value identified: 101 CourseNana.COM

Updated original value: 10101010051 CourseNana.COM

Example Execution #2 Explained: CourseNana.COM

When multiple occurrences of the same largest number exists then alter the one at the lowest position. CourseNana.COM

Example Execution #3: CourseNana.COM

Enter a positive integer value -> 886428846 Enter desired number of digits -> 4 CourseNana.COM

Max value identified: 8864 CourseNana.COM

Updated original value: 443228846 CourseNana.COM

Example Execution #3 Explained: CourseNana.COM

Seeking four digits and the largest consecutive value is at the four highest positions within the original number. CourseNana.COM

All course programming and documentation standards are in effect for this and each assignment this semester. Please review this document! CourseNana.COM

CourseNana.COM

Checkpoints During Lab #8: CourseNana.COM

TA Verification CourseNana.COM

1 – Identify Tasks CourseNana.COM

In addition to considering the user-defined functions for this problem your group should also consider where in the program the repetitive processes will be found. CourseNana.COM

2A – The main Function CourseNana.COM

Review what is expected to remain in the main function and what should be factored into user-defined functions. Course standards have something to say about the use of selection and repetition in the main function. CourseNana.COM

2B – Function Declarations and Calls CourseNana.COM

Add the function declarations to the global declaration sectionoftheprogram. Completethemainfunctionwith the necessary function calls. CourseNana.COM

3 – Implementation of Input Functions CourseNana.COM

Demonstrate input, and its validation, operates as expected. CourseNana.COM

4 – Implementation of Calculations CourseNana.COM

This is likely multiple functions, use diagnostic print statements generously to verify correctness. CourseNana.COM

5 – Implementation of Output Function CourseNana.COM

Final output matches expected, additional test cases created to further demonstrate correctness of logic. CourseNana.COM

6 – Successful Submission CourseNana.COM

Save, compile, and test program. Submit and review report related to expected output and course standards. CourseNana.COM

Additional Requirements: CourseNana.COM

  1. Add the lab assignment header (vi shortcut :hlb while in command mode) to the top of your program. An appropriate description of your program must be included in the assignment header.
  2. Each of the example executions provided for your reference represents a single execution of the program. Your program must accept input and produce output exactly as demonstrated in the example executions. Your program will be tested with the data seen in the example executions and an unknown number of additional tests making use of reasonable data. See the problem description and example executions #3 and #4 for input validation expectations. All input will be in the integer family of data types.
  3. For this assignment you will be required to implement the user-defined functions (from chapter 4). Failing to follow course standards as they relate to good user-defined function use will result in a zero for this assignment.
  4. Revisit course standards as it relates to a good use of user-defined functions, what is acceptable to retain in themainfunction,andwhenpassingparametersbyaddressisappropriate(notespacketpage108). In many cases user-defined function use should result in a main function that only declares variables and makes function calls.
  5. Course standards prohibit the use of programming concepts not yet introduced in lecture. For this assignment you can consider all material in the first six chapters of the book, notes, and lectures to be acceptable for use. Theuseofarrayswouldviolaterequirementsofthisassignmentandresultinnocreditbeingawardedfor your effort.
  6. A program MUST compile, be submitted through Vocareum as demonstrated during the first lab meeting of the semester, and submitted prior to the posted due date to be considered for credit. The C-file you submit must be named exactly: lb08.c

Course Programming and Documentation Standards Reminders: CourseNana.COM

  • Code found inside the body of relevant selection and repetition constructs must be indented two additional spaces.
  • Make use of { and } with all relevant selection and repetition constructs.
  • See page 258 of your C programming text regarding the proper indentation for a switch construct.
  • Use the course function header (vi shortcut :hfx while in command mode) for every user-defined function in your program.

Listandcommentallparameterstoafunction,oneperline,inthecoursefunctionheader.
Allfunctiondeclarationswillappearintheglobaldeclarationsectionofyourprogram.
Theuser-definedfunctiondefinitionswillappearinyourprogramafterthemainfunction. CourseNana.COM

  • Indent all code found within the main function exactly two spaces.
  • Maximize your use of symbolic/defined constants and minimize your use of literal constants.
  • Place a single space between all operators and operands.
  • Comment all variables to the right of each declaration. Declare only one variable per line.
  • Notice that several programs (see program 2-9 on pages 74-75) in the programming text use a single line comment to indicate the start of the local declaration and executable statement sections of the main function. At no point during the semester should these two sections ever overlap. You might consider adopting this

habit of commenting the start of each section to help you avoid this mistake. CourseNana.COM

  • Select meaningful identifiers (names) for all variables in your program.
  • Do not single (or double) space the entire program, use blank lines when appropriate.

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
US代写,Purdue代写,Purdue University代写,CS 159代写,CS159代写,C Programming代写,Integer代写,US代编,Purdue代编,Purdue University代编,CS 159代编,CS159代编,C Programming代编,Integer代编,US代考,Purdue代考,Purdue University代考,CS 159代考,CS159代考,C Programming代考,Integer代考,UShelp,Purduehelp,Purdue Universityhelp,CS 159help,CS159help,C Programminghelp,Integerhelp,US作业代写,Purdue作业代写,Purdue University作业代写,CS 159作业代写,CS159作业代写,C Programming作业代写,Integer作业代写,US编程代写,Purdue编程代写,Purdue University编程代写,CS 159编程代写,CS159编程代写,C Programming编程代写,Integer编程代写,USprogramming help,Purdueprogramming help,Purdue Universityprogramming help,CS 159programming help,CS159programming help,C Programmingprogramming help,Integerprogramming help,USassignment help,Purdueassignment help,Purdue Universityassignment help,CS 159assignment help,CS159assignment help,C Programmingassignment help,Integerassignment help,USsolution,Purduesolution,Purdue Universitysolution,CS 159solution,CS159solution,C Programmingsolution,Integersolution,