Briefly explain the role of the pre-processor

Assignment Help Computer Engineering
Reference no: EM131293385

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.

Reference no: EM131293385

Questions Cloud

Evaluate influence that corporate social responsibility has : Identify the potential ethical implications associated with this decision. Discuss the application of critical thinking to corporate social responsibility. Evaluate the influence that corporate social responsibility has on the organization.
Find the best hypothesis that a p proximates f : For each of the following learning models, find the best hypothesis that a p proximates f in the mean squared error sense.
Write a paper about world meteorological organization : Write a paper about World Meteorological Organization and also Expalin in detail.
What do you believe is the single most influential force : What do you believe is the single most influential force in today's society that sets the tone for an individual's personal values and why? Does this force affect Christians positively or negatively?
Briefly explain the role of the pre-processor : Briefly explain the role of the pre-processor in the compilation of a program - What does the -D in the following command do and why would we want to use it? g++ -D DEBUG sourceFile.cpp
Board of governors of the federal reserve website : Visit the Board of Governors of the Federal Reserve website and read the latest Federal Open Market Committee (FOMC) statement which discusses the current type of monetary policy which the Federal Reserve is implementing:
Write a paper on ideologies and current correctional trends : prepare a  research on correction ideologies and current correctional trends. In a 3 page paper, compare and contrast correction ideologies to current correctional trends.
What key persuasive techniques used in consumer advertising : What are the key persuasive techniques used in consumer advertising? Illustrate with specific examples, explaining how each technique works.
What are the common education problems : A) What are the common education problems we are facing? (i) Why are the problems common in this region? (ii)What caused the problems in each countries?

Reviews

Write a Review

Computer Engineering Questions & Answers

  The organization requires a domain name

find out what domain name is available for the company. Judge whether you would use a .com, .org, or .net for the Web address.The organization requires a domain name

  Write program that inputs a word representing binary number

Write a program that inputs a word representing a binary number (0s and 1s). First your program should verify that it is indeed a binary number, that is the number contains only 0s and 1s.

  Assume a direct access file consists of sectors

assume a direct access file consists of sectors with 1024 byte capacity. Suppose also that records are 32 bytes long. On which logical sector do the following logical records lie? What is the relative record number in the sector?

  Question1 why is it significant to control changes to asset

question1. why is it significant to control changes to asset baselines?2. why is the labelling process approached

  Assingment 1 social media crm historyusing your book and

assingment 1 social media crm historyusing your book and many outside resources research the history of the use of

  Describe the role of mutual legal assistance treaties mlats

question due to the global nature of the internet evidence of u.s. targeted cybercrimes is increasingly only available

  Program that continuously outputs random numbers

Write down a code in Java that continuously outputs random numbers between 0 and 10000 until a number which is divisible by 5 is encountered.

  Developing uml one state diagram

How the system responds to the external and/or internal events by developing a UML ONE State Diagram.

  Why is an object (oop) a module

Why is an object (OOP) a module

  Analyze the use of gestures in ipads

Analyze the use of gestures in iPads. Address how users feel about gestures. Evaluate how users feel about the user input when it comes to filling out complicated forms on the iPad.

  Develop and prototype a new interface design

Develop and prototype a new interface design for the system's functions using a graphical user interface. Also, develop a set of real use cases for your new interface.

  Write ieee floating point representation of the following

Write IEEE floating point representation of the following decimal numbers.

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