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

USPurduePurdue UniversityCS 159CS159C ProgrammingInteger

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

Statement

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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.

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

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

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

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

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

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

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.

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

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.

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

 Pretest Loop Post-test Loop # of times loop control expression is evaluated # of times loop control expression is evaluated # of times the loop iterates # of times the loop iterates Minimum # of times loop is iterated Minimum # of times loop is iterated

Use the table below to trace the execution of the loop provided:

 int x = 3415263; int ct = 0; while(x > 0) {if(x % 2 == 0) { ct++; } x = x / 10; } End of Iteration # Value of X Value of CT 1 2 3 4 5 6 7 8

Use the table below to trace the execution of the loop provided:

 int x = 3415263; int ct = 0; do { x = x / 10; if(x % 2 == 0) { ct++; } }while(x > 0); End of Iteration # Value of X Value of CT 1 2 3 4 5 6 7 8

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

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.

 Role: Description: Every member will rotate roles at every checkpoint. Driver 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. Navigator 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. Manager 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.

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.

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.

 Example Execution #1: Enter a positive integer value -> 246895731 Enter desired number of digits -> 2 Max value identified: 95 Updated original value: 246848731 Example Execution #1 Explained: 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. Example Execution #2: Enter a positive integer value -> 10101010101 Enter desired number of digits -> 3 Max value identified: 101 Updated original value: 10101010051 Example Execution #2 Explained: When multiple occurrences of the same largest number exists then alter the one at the lowest position. Example Execution #3: Enter a positive integer value -> 886428846 Enter desired number of digits -> 4 Max value identified: 8864 Updated original value: 443228846 Example Execution #3 Explained: Seeking four digits and the largest consecutive value is at the four highest positions within the original number.

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

 Checkpoints During Lab #8: TA Verification 1 – Identify Tasks 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. 2A – The main Function 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. 2B – Function Declarations and Calls Add the function declarations to the global declaration sectionoftheprogram. Completethemainfunctionwith the necessary function calls. 3 – Implementation of Input Functions Demonstrate input, and its validation, operates as expected. 4 – Implementation of Calculations This is likely multiple functions, use diagnostic print statements generously to verify correctness. 5 – Implementation of Output Function Final output matches expected, additional test cases created to further demonstrate correctness of logic. 6 – Successful Submission Save, compile, and test program. Submit and review report related to expected output and course standards.

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:

• 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.

Allfunctiondeclarationswillappearintheglobaldeclarationsectionofyourprogram.
Theuser-definedfunctiondefinitionswillappearinyourprogramafterthemainfunction.

• 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.

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

## Get in Touch with Our Experts

QQ
WeChat
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,