Provide proper documentation as required in the pas

Assignment Help Computer Engineering
Reference no: EM131270296

Question #1 - Tracing Programs

As with previous exams, trace the following program by tracking the values of all variables in the table provided below.

Program to Trace
#include <stdio.h>
int main(){
1 int array[5] = { 0,1,2,3,4} ;
2 int * p1, **p2 ;
3 int * parray[2] = { NULL , NULL };
4 p1= & array[2] ;
5 *p1 = 20 ;
6 p2 = & p1 ;
7 ** p2 = 30 ;
8 parray[0] = & array[0];
9 parray[1] = & **p2;
10 *parray[0] = 30 ;
11 *parray[1] = 300;
}

Trace Table to Fill

In order to make it easier for you to trace pointer values, here is a table telling you the memory addresses of all the variables in the above program.

 

Variables

array[0] to array[4]

p1

p2

parray[0] to parray[1]

Memory Address

1000

1004

1008

1012

1016

1020

1024

1028

1032

The following table is where you will be tracing your program;
Use ??? to denote an undefined value; e.g. non-initialized variable.
Use error to denote the dereference of a NULL or undefined pointer.

As for previous exam, a given line should only modify the columns of the variables which it modified. However, because we use pointers, you might have to modify other columns if your line just dereferenced a pointer to modify another variable.

Question #2 - Testing Programs

You are going to write tests for a function. Unlike previous exams, we do not provide you with the source of this function but only its requirements. Therefore, your tests will have to allow us to verify that an arbitrary implementation fulfills requirements.

Program Requirements

The signature / prototype of the function;

char* str_reverse(char * str);

Its requirements are as follows;
Work with any value for the char*

Return a newly allocated string which is reversed compared to the original

Return a copy of an empty string

Return NULL if the string is NULL

Returns NULL if the string is more than 10 characters long, including end of string marker

Tests Table to Fill

Feel free to add / remove rows if necessary

Question #3 - Refactoring Programs

Refactor the following code; i.e. improve its quality without modifying its behavior;

Use meaningful names for variables, parameters & functions

Provide proper documentation as required in the PAs

Provide proper indentation & programming style similar to the examples from the textbook, videos & PAs

Remove useless code
Simplify program
Improve performance
Improve readability

Handle bad parameter values by returning NULL

Handle memory allocation problems by returning NULL

You will provide your version in the "Your Modified Version" subsection which is already pre-filled with the original. Then, for each improvement you applied, use the table in the "Summary" subsection to explain what you did & why you did it.

Program to Refactor

Summary of Improvements

Feel free to add rows to, or remove rows from, this table as needed;

Question #4 - Debugging Programs

The following function has all sorts of problems in implementing the requirements. We need you to list the errors you found in the table below along with how you would fix them. You will then provide the fixed version of the function. Here is the documentation for the function. You will use this information as requirements;

Role

Takes two non-null, non-empty, strings of same length, containing only lower-case alphabetical characters

Return a newly allocated string of same length than s1

For each character at index n in this new string, its ASCII index should be 141 plus half of the positive difference between the ASCII values of the characters at index n in s1 & s2

Parameters

s1 & s2 non-null, non-empty strings of same size

Return Values

NULL if the parameters are not what we expected
NULL if memory allocation was a problem
Address of a newly allocated string as described above
Bugs Table

Identify each bug you find & provide the lines # where it happens. In addition, explain what the problem was, then how you fixed it. If the same bug appears at different line, just enter it one time in the table but specify all the lines where it happens.

Apply all the fixes you listed in the table to the code below to make it your fixed version. Please note that if a bug is fixed below but not in the table, or the other way around, you won't get credit for it. You need to have both the bug and its explanations in the table and have it fixed below.

Reference no: EM131270296

Questions Cloud

How much income is spent on beer : What will be his optimal consumption choices of beer and cheese given the original prices of Pb=$2 and Pc=$5 and income =$500? How much income is spent on beer? How much on cheese?
What is the maximum operating frequency of the circuit : How much clock skew can the circuit tolerate if it must operate at 2 GHz?
The cost of providing satellite tv for all three towns : A satellite TV station is to be located at P(x, y) so that the sum of the squares of the distances from P to the three towns A, B, and C is a minimum. - Find the coordinates of P, the location that will minimize the cost of providing satellite TV f..
Variables influence the demand for a normal good : What variables influence the demand for a normal good? Explain why a reduction in the price of a normal good does not increase the demand for that good.
Provide proper documentation as required in the pas : Provide proper documentation as required in the PAs. Provide proper indentation & programming style similar to the examples from the textbook, videos & PAs.
Determining the monopoly market equilibrium : Moving Equilibrium. Show the effect of each on the monopoly market equilibrium; you don't need to have exact answers but explain the direction of change in the demand and/or marginal cost curves.
Characterized by the following inverse demand : Suppose perfectly competitive market conditions are characterized by the following inverse demand and inverse supply functions: P = 100 - 5Q and P = 10 + 5Q. The demand curve facing an individual firm operating in this market is:
Find the coordinates of p : Repeat Problem, replacing the coordinates of B with B(6, 9) and the coordinates of C with C(9, 0).- Find the coordinates of P, the location that will minimize the cost of providing satellite TV for all three towns.
Determining the human capital : Country A has twice as many workers as Country B. Country A also has twice as much physical capital, twice as much human capital, and access to twice as many natural resources as Country B. Assuming constant-returns to scale, which of the followin..

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd