Explore BrainMass


Data Structures and Tree-Traversal Function

Trace the following tree-traversal function, f(), and describe its action: int f(tnode<int> *t) { int sLeft, sRight; if (t != NULL) { sLeft = f(t->left); sRight = f(t->right); return t->nodeValue + sLeft + sRight; } else return 0; } Please provide a complete

Binary Trees and Tree-Traversal

Trace the following tree-traversal function, f(), and describe its action: template <typename T> int f(tnode<T> *t) { int n = 0, leftValue, rightValue; if (t != NULL) { if (t ->left != NULL || t->right != NULL) n++; leftValue = f(t->left); rightValue = f(t->right);

C++ Programming: Mortgage Payment

Please modify the attached program so it will satisfy and meet below requirements: Write the program as a procedural C++ program. Calculate and display the mortgage payment amount using the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage as input by the user. Allow the user to loop back

Moving Elements in C++ Queue Using Template

See attached file. Write a function template<typename T> void n2front (queue<T>& q, int n); that moves the nth element (counting from the front, which is element 1) of the queue to the front, leaving the order of all other elements unchanged. The function throws the rangeError exception if n < 1 or n> q.size(). The fig

Data Structures with C++ Using STL

Declare a stack, queue, and priority queue of integers, as follows: stack<int> s; queue<int> q; priority_queue<int> pq; Assume that you input the integer sequence 5 8 12 15 1 3 18 25 18 35 2 55 and insert each value into each container in the order given. What is the output of the following statements? while (

Data Structures with C++ Using STL

List the elements in the queue after each of the following operations: queue<int> intQueue; intQueue.push(18); intQueue.push(2); intQueue.push(intQueue.front()); intQueue.push(intQueue.front()); intQueue.pop(); Please provide a complete program if it makes sense.

Data Structures with C++ Using STL

What is the output from the following sequence of stack operations? stack<int> intStack; int x, y = 3; intStack.push(8); intStack.push(9); intStack.push(y); x = intStack.top(); intStack.pop(); intStack.push(18); x = intStack.top(); intStack.pop(); intStackpush(22); while (!intStack.empty()) { y = intStack.top();

isbns from two different tables

I have a query that starts with the line: SELECT books.isbn, order_lines.isbn ...why would I want to see isbns from two different tables? What sort of query would warrant that - an inner join or an outer join? Assume the table "books" contains books that the company stocks. Assume the table order_lines only

trace the codes and display the resulting elements in a list

Trace the following code, and display the resulting elements in the list: int arr[] = (1, 2, 3, 4); int arrSize = sizeof(arr)/sizeof(int); list intList(arr, arr+arrSize); list::iterator iter = intList.begin(); int i; for (i=1; i <= arrSize; i++) intList.insert(iter++, i); Please provide a complete program i

Tranfer an array to a list

Consider the C++ array int arr[] = (-15, 5, 35, -19, -12, 17, -4); int arrSize = sizeof(arr)/sizeof(int); (a) Declare the list object intList that holds the integers from the array arr. (b) Declare the iterator iter for an integer list. (c) Initialize the iterator iter to the beginning of the list intList. (d)

Procedural C++ Mortgage Program

Please help me write the program as a procedural C++ program and using a loan amount of $200,000, a term of 30 years, and an interest rate of 5.75%. Insert comments in the program to document the program.

Data Structures with C++ (STL)

Consider the class declaration class demoClass { public: // assign arguments as initial values for the data members demoClass(int a = 5, int b = 10); // function returns the maximum of itemA and itemB // int max() const; private: int itemA, itemB; }; (a) Give t

C++ Linked List Pointers

Given the attached code (see file), what is the values of the following expressions. They may be undefined or the boolean expression may be invalid a) firstptr->next->firstname b) firstptr->next-next->SSN c) firstptr->next==lastptr d) currptr->next->lastname e) currptr->next->lastname f) firstptr==lastptr->next g)fi


Using the attached file all numbers class do the following: - write a template function for the class called Add15() that adds 15 to each of the two numbers and display the result - write a template function for the class called multiplybypoints5() that multiples 0.5 to each numbers in the parameter list and display result

C++ Problem

Program that does the following: delcale an integer (var1) declare a pointer (ptr1) that points to var1 declare a reference (ref1) to var1 assign the address of var1 to ptr1 print the value of var1 using the pointer use the ref1 to change the value of var1 to var15 print the value of var1 using the ref1

Visual C++

The following class uses composition to define a line object in terms of two point objects. class line { public: Point startingpoint(); point endingpoint(); float length(); line (int startX, int startY, int endX, int endY); private: point startPoint; point endPoint: }; 1) write a fucntin defintion for the Lin

Visual C++

Give the class declaration class point { public: int xcoordinate(); int ycoordinate(); point(in initializeX, in initialize Y); private: int x; int y; }; 1: Suppose we have a type declaration as follows: enum status {on, off}; declare a class Pixel that inherits from class Point. Class Pixel will have an ad

Visual C++ Classes

Write a program that read in an integer. If the integer is a negative number, catch the exception and print an error message "Invalid Integer: value negative" and prompt the user for another number. If the integer is zero, catch the exception and print a message, "Integer cannot be zero, and end the program. Otherwise, just pri

Write a C++ program to output the binary

Write a C++ program to output the binary (base-2) representation of a decimal integer. The algorithm for this conversion is to be repeated dividing the decimal number by 2 until it is 0. Each division produces a remainder of 0 or 1 which becomes a digit in the binary numbers. example the decimal number 25 25/2 = 12 rema

Visual C++

Write a C++ value returning function that implements the recursive formula F(n) = F(n-1) + F(n+2) with base cases F(0)=1 and F(1) =1

Priority Queues (C++ Programming)

I need a program that uses the structure of priority queues that implement the right way to take care of an emergency room. Priorities: 1. Respiratory failure 2. No circulation 3. Hemorrhages It should be taken in consideration that if exists two persons with the same level of priority the first one to arrive is the fir

Operating System Process Simulator in C++

The program must be done in C++. The program is not in Visual C++, in other words it must show everything in the command prompt window. Please use cout and cin and not printf and scanf nor other C standards See attached file for full problem description.

Inheritance - SalariedEmployee - C++

Write a program that uses the class SalariedEmployee shown below. Your program is to define a class called Administrator, which is to be derived from the class SalariedEmployee. You are allowed to change private in the base class to protected. You are to supply the following additional data and function members: A member vari

Strings and Vectors C++

Write a program that can be used to train the user to use less sexist language by suggesting alternative versions of sentences given by the user. The program will ask for a sentence, read the sentence into a string variable, and replace all occurences of masculine pronouns with gender-neutral pronouns. For example, it will repla

Strings and Vectors C++

Please enhance this program. Write the definition of the readAndCount function. The function should read the input line, character by character, counting the number of words (a sequence of letters) and the number of occurrences of each letter. The array to hold the number of occurrences of each letter is the parameter let

C++ Names.cpp

Write a program that reads a person's name in the following format: first name, then middle name or initial, and then last name. The program then outputs the name in the following format: Last_Name, First_Name Middle_Initial. For example, the input Mary Average User should produce the output: User, Mary A. The inp

queue and stack in C++

I need two separately programs from the same code. 1.) Modified the code so it has a Pop() function that makes the function of a Queue. Example: Input: Enter Id: 1 Enter Name: Ana Enter Id: 2 Enter Name: Carlos Ouput: (After a pop): Id: 1 name: Ana 2.) Modified the code so it has

Friends and Overloading Operators C++

Complete and test this exercise. Implement the default constructor and the constructor with one int parameter. Overload the + and - operators to add and subtract percents. Also, overload the * operator to allow multiplication of a percent by an integer. Write a program to test all the member functions and overloaded operator