Ask Computer Engineering Expert

1. Briefly explain the role of the pre-processor in the compilation of a program.

2. What does the -D in the following command do and why would we want to use it? g++ -D DEBUG sourceFile.cpp

3. Consider the source files sort.h, sort.cpp, things.h, things.cpp and main.cpp. The header files sort.h and things.h are included in main.cpp. The source file sort.cpp includes the header sort.h and the source file things.cpp includes the header file things.h.

Define a makefile that makes a program task from the source files given above. It requires that the make command will not re-compile the source files if they are up to date.

4. Describe what is meant by the term white box testing and explain the advantages and disadvantages of white box testing?

5. What is a segmentation fault? Give an example of how one might occur.

6. Define the structure Record as following

struct Record {
char name[50];
int age;
double payRate;
};
Implement a function saveRecords(char *filename, Record recs[], int size) to save the records into a binary file.

7. Define the structure Employee as following
struct Employee {
int id;
char name[50};
double payRate;
};
Write a function with prototype:
int linearProbingsearch(Employee recs[], int size, int number);

to perform a hashing search with linear probing by given target id number. The first argument is the hash table to be searched, the second argument indicates the size of the array and the third argument is the value (id number) to search for. The return value should be the index of the value in the array, or -1 if the value is not in the array. Assume the hash function int hashf(int) has been defined.

8 Quicksort is a recursive function which calls partition function by using a pivot. Use the method taught in the lectures to demonstrate the quicksort by write the data sequences after each partition be called for the following data array. You may choose the first element as a pivot for each sub array. Put underline for each pivot selected in the partition.
23 15 19 28 36 11 63 7 44 17

9. What does it mean to assign a pointer to another same type of pointer?

10. I want a function which takes an integer between 1 and 7 and returns a pointer to a string containing the corresponding day of the week. The following function is proposed:
string* days (int i)
string week[7] = {"sun", "mon", "tue", "wed", "thu", "fri", "sat"};
int * ptr = week;
if (i<=7 && i>0)
return (&ptr[i-1]);
else
return NULL;

a. What is wrong with this function?

b. How could you fix it?

11. A data file contains a database of records. It may be considered to be a binary file. A program is required to read the record which is the third from the end of the file (note, the last record is considered first from the end) and edit its authorlD. The record is defined as follows
struct Record
{
char name[12];
int authorlD;
int pubId;
1;
a. If the file is called magazine.dat, how might we open the file so that the resulting stream fin can both read and write the file in binary?

b. Write the code to get the number of bytes in the file and store the value in the variable fileSize. (1 Mark)

c. To read in the record third from the end, the following pseudocode is developed:

    1. Position read marker 3 records before the end of the file

    2. Read in a single record into the variable author.
Write the two C++ statements needed to perform these tasks. You may assume that author is already declared as a Record.

d. A new authorlD has been successfully requested from the user and is stored in an integer newId. Assuming that the write marker of the stream fin is currently positioned at the start of the correct record, write the code required to reposition the write marker and then write newId only into the correct location.

12. You have some code for an old linked list implementation which takes the name and booking size for a customer. It works well, but only works for customer records. It has the following prototypes:
struct customer
{
char name[21];
short int bookingSize;
customer * next;
} ;
void init(custPtr &head);
void add (const char name[], int size, customer* &head); bool remove (char name[], int &size, customer* &head);

a. Explain how we might use a typedef to make this linked list more generic and rewrite the above code to show how the prototypes might change.

b. What is the main limitation of using typedef to achieve generic code rather than another method such as void* and function pointers?

13. The following function returns the volume of a rectangular prism, or -1 if the dimensions are out of range.
Int volume(double w, double h, double d) {
if (w < 0 ll h< 0 II d< 0)
return -1;
vol = w*h*d;
return vol;
}
a. Rewrite it so that it throws an exception if the inputs are out of range.

b. Write a code fragment which tries to call your rewritten volume function with and prints "invalid arguments" if it catches an out_of_range exception.

2015 Sept 16 CSCI124 WG Spring 2015 Page 5 of 9

14. Write short answers to the following questions:

a. What does a mutator function mean for a class?

b. List three member functions which will be implicitly declared if they are not explicitly declared.

c. What does a friend function mean for a class?

15. Write C++ code for the following questions:

a. Define a class Department. A Department has name, building number, manager name and budget. Define a manager function that set all data members' values from parameters. Define an access function to print out all the data members to an ostream.

b. Implement the member functions that defined in the question a. just above. These implementations should be placed outside of the class definition.
c. Write a sketch code to declare a Department instance with the proper values and print out the attributes of the Department. The values are up to you.

16. Write C++ code for the following questions:

a. Define a class MyString consist of two data members. One is a char pointer; another one is an integer stores the size of the dynamic array. Define the default constructor, initialization constructor, copy constructor, destructor and print function for the class.

b. Implement the constructors, destructor and the print function that defined in the question a just above outside the class definition. The copy constructor makes a deep copy from a MyString object.

c. Write a sketch code to declare a MyString instance by initialization constructor, declare another MyString instance with a copy constructor. Print out the two MyString instances.

17. Define a structure Node and a class Stack as following struct Node {
int data;
Node *next;
1 ;
class Stack {
private:
Node *head; int number; public:
Stack() f
head = NULL;
number = 0;

1 ;

Write C++ code for the following questions:

a. Implement the member functions defined above for the class Stack.
b. Define and Implement the destructor for the class Stack.

18. Define classes as following
struct DNode f int data; DNode *prev;
DNode *next;
1 ;
class Deque {
private:
DNode *head;
DequeNode *tail; public:
Deque();
Deque(const Deque &); -Deque();
void push front(int); void push_back(int); int front();
int back();
void pop_front(); void pop back(); void insert(int); void printAll(std::ostream &);
1 ;
Write C++ code for the following questions:

a. Implement the member function insert(int) for the class Deque. The function inserts a new entry in the deque according to the ascending order. The deque might be empty.

b. Implement the copy constructor of the class Deque to make a deep copy from a Deque object. Assume the other member functions except insert(int) have been implemented.

c. Implement the member function printAll(std::ostream &). The function prints all the data values that stored in the deque to the output stream.

19. Define classes as follows
struct BTreeNode 1
int data;
BTreeNode *left;
BTreeNode *right;
I ;
class BST {
private:
BTreeNode *root; public:
BST();
-BST();
bool isEmpty(); void insert(int);
void preorderTraversal();
void inorderTraversal();
void postorderTraversal();
} ;
Write C++ code for the following questions:

a. Implement the member function insert(int). The function inserts a new entry into the binary search tree.

b. Implement the member function preorderTraversal(). The function prints out all the data values of a binary search tree by preorder traversal.

Hint: It is easier to write the function in a recursive manner. You may declare additional functions if you wish.

20. Write short answers to the following questions:
a. What is a complete binary tree?
b. Given the initial data as following
119 21 49 202 135 421 127
Sort the data above using the radixsort taught in the lectures. Demonstrate your answers by draw the buckets and extract elements sequences for each pass.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92048049
  • Price:- $150

Guranteed 48 Hours Delivery, In Price:- $150

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As