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

  Implement a java application that reads tweets

Description: The goal of this assignment is to implement a Java application that reads tweets from both the Twitter Streaming API and preloaded log file and finds the trending topics for a given set of languages and periods

  Define and discuss importanceof nonlinear

define and discuss importanceof nonlinear optimizationdiscuss excel solver and its importance to the optimization

  The least number of telephones an end office

take a simple telephone network consisting of two end offices and one intermediate switch with a 1-MHz full-duplex trunk between each end office and the intermediate switch.

  How would you begin an interview with a knowledgeable user

Suppose that your goal is to create a set of DFDs. How would you begin an interview with a knowledgeable user? How would you begin a JAD session?

  Assume that intlist1 and intlist2 are list containers

assume that intList1 and intList2 are list containers.

  Propose a wiring plan for network servers

Propose a wiring plan for network servers.

  Find out whether an integer is a prime number

An integer greater than 1 is a prime number if its only divisor is 1 or itself. For in case, isPrime (11) returns true, and isPrime (9) returns false.

  Draw a block diagram describing the system design

Their movements are fed into a computer that finds the differences between their joint positions and provides proportional vibrational strength feed back to the student. Draw a block diagram describing the system design.

  How would error-correction requirement of an optical storage

How would the error-correction requirements of an optical document storage system differ from the error-correction requirements of the same information stored in textual form?

  Compute the output of a sigmoid neuron

Write out Equation a′=σ(wa+b). in component form, and verify that it gives the same result as the rule 4 for computing the output of a sigmoid neuron.

  Design a logical and physical topographical layout

Design a logical and physical topographical layout of the current and planned network through the use of graphical tools in Microsoft Word or Visio, or an open source alternative such as Dia.

  Prepare program that reads a text file and stores the data

Can you prepare the program that reads a text file and stores the data into an Object called fruit Say the text file data is as follows for

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