This essay has been submitted by a student. This is not an example of the work written by professional essay writers.
Uncategorized

ECM2433

Pssst… we can write an original essay just for you.

Any subject. Any type of essay. We’ll even meet a 3-hour deadline.

GET YOUR PRICE

writers online

ECM2433

Question 1

  1. If the condition of the if statement evaluates to 1, the program will satisfy that there is available memory for processes.
  2. The memory requested is 8*sizeof(short int) = 16bytes total
  • Declaring the pointer before the line

a.)

‘#include guard’ is a construct used in the C program to prevent header contents from being used more than once.

b.)

argc (ARGument Count) is int and stores the number of command-line arguments passed by the user, including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for argument and one for program name)

 

argv(ARGument Vector) is an array of character pointers listing all the arguments.

d.)

A memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory, which is no longer needed, is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.

 

A memory leak is caused when you allocated memory, haven’t yet deallocated it, and you will never be able to deallocate it because you can’t access it anymore.

 

e.)

The longjump() function is considered dangerous where because goto is limited to the current, local scope, longjmp can span outside of the current scope and across functions.

 

Uses: The longjump() transfers control the pointe which is pointed by setjump().

 

f.)

In c++ static members are variables which are declared with the static keyword; thus, only a single copy of the variable creates for all objects.

Advantages: Any changes in the static data member through one member function will reflect in all other object’s member functions.

Difference: Static members are created and initialised only once while nonstatic data members are created again and again.

 

g.)

Yes, we can define the same access specifiers multiple times.

The scope of one access specifiers defines the accessibility of an Object and its members.

The security characteristic is used to determine whether a class member is made public or private.

h.)

Size is not allowed to differ between multiple compilers. The size of a vector is the number of elements that it contains, which is directly controlled by how many elements you put into the vector.

Capacity is the amount of space that the vector is currently using. Under the hood, a vector just uses an array.

Code explain:

The size of memory reserved is 32bytes while the capacity is 9*8bits+1, giving a total of 73bits.

Question 2

 

a.)

A function prototype refers to a declaration of a function which defines the function’s name and type signature (arity, data types of parameters, and return type), but omits the function body.

The void keyword specifies  that the two  functions take no parameters

b.)

Since the size of the short int is 2bytes, unallocated space is held which is not effective. One approach to improve the code, the boolean data type can be used to represent 0 and 1 as false or true, respectively. A second method to improve the code is by using signed int minimise wasted space where the sizeof(char) is 1byte by the standard, and the number of bits used is given by CHAR_BIT, which is normally 8 bits.

 

unsigned int getVoyagerBit (unsigned int num)

{

Int num = 100;

unsigned int count = sizeof(num) * 8 – 1;

unsigned int

bitsequence = num;

 

num >>= 1;

while(num)

{

bitsequence <<= 1;

itsequence |= num & 1;

num >>= 1;

count–;

}

bitsequence <<= count;

return bitsequence;

}

 

 

 

d.)

 

unsigned char makeByte (unsigned char *bits){

unsigned int sum = 0;

for(int i = 7; i >= 0; i–)  {

sum += bits[i];

sum<<=1;

}

return sum;}

 

e.)

The union will have unit8_t and a struct containing 8 one-bit bit-fields. Using bitwise operations, combine union and bit-fields to extract bits depending on endianness.

 

f.)

The machine uses big-endian.

 

Question 3

 

a.)

The C++ code has an error in inheritance due to use of the wrong specifier, making it impossible to access private members of the ‘point’ class from the ‘line’ class.

There is no initialisation of base class members making the point object not be constructed properly.

b.)

  1. D

True. Constructors are necessary to initialise variables when the program is executed the main function first calls the constructor. In cases where it is not given, the compiler adds one by default.

 

  1. True. The compiler implicitly assigns a default value is assigned to the constructors, and they cannot take parameters.
  • False. Default values on constructors are only assigned by the compiler when the programmer does not give any.
  1. True. The compiler initialisation enumerates and sets the class members one by one giving them default parameters.

c.)

A friend function that is a “friend” of a given class is a function that is given the same access as methods to private and protected data.

No. Well encapsulated friends can not violate encapsulation since both classes both have exactly the same authority with respect to accessing the class’s non-public parts.

Friendship is not reciprocal because classes do not automatically trust and give access to all its objects.

d.)

The deque container is best for reading the unknown double items. The container will act like a double-ended queue that can act as a stack or queue. This choice is recommended because it is good when you are not sure about the number of elements and also enables the sorting of elements through data-element access in a serial manner.

The vector container is recommended for the second task. The vector container provides a  dynamic-array class through which the internal memory is always allocated an array. This approach is useful when the size of the data is known, enabling access to items in all locations in the file.

 

 

 

 

 

 

 

  Remember! This is just a sample.

Save time and get your custom paper from our expert writers

 Get started in just 3 minutes
 Sit back relax and leave the writing to us
 Sources and citations are provided
 100% Plagiarism free
error: Content is protected !!
×
Hi, my name is Jenn 👋

In case you can’t find a sample example, our professional writers are ready to help you with writing your own paper. All you need to do is fill out a short form and submit an order

Check Out the Form
Need Help?
Dont be shy to ask