# Computer Science

## Write a C program using a nested for loop to graph array element values with histograms. The program should read numbers from an array and graphs the information in the form of a bar chart or histogram – each number is printed, then a bar consisting of that many asterisks (*) is printed beside the number. An example of output (histogram) is shown below:

EXPERT ANSWER #include <stdio.h> int main(){int arr={10,24,7,12,5};for(int i=0;i<5;i++){printf(“%-3d: “,arr[i]);for(int j=0;j<arr[i];j++){printf(“*”);}printf(“\n”);}return 0;}

## write any program that has a base template class and a derived template class and main to run them.

write any program that has a base template class and a derived template class and main to run them. Your program must have template base class that is inherited to a template derived class, and the main program that runs an instance of the derived class. You don’t need to have an output to the …

## a. 3. (4 pts) Simplify the following Boolean expression: (X+Y)(X’+Z)Z’Y’ + X(Y+Z) + (ZYX+Y)(ZYX+XZ) The answer should be X(Y+Z). Note that there are several ways to perform simplification. Show all steps of the simplification process. (1 pt) Perform simplification using Boolean laws b. (1 pt) Prove equality of these two Boolean expressions using a truth table (2 pt) Show that the simplification process in (a) has significantly reduced the number of logic gates required to implement the expression by: Drawing the two logic networks (network for the original expression and network for the reduced expression) using only 2-input AND and OR gates. You should assume that you can use complemented (inverted) variables as inputs to your networks. You should not attempt to simplify the expressions, but you should reuse gates, if possible. The diagrams must be neat enough for the marker to understand and grade them. Answering how many gates have been “saved” by this simplification c.

EXPERT ANSWER 3. a. Apply the commutative law: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(((X⋅Y⋅Z)+Y)⋅((X⋅Y⋅Z)+(X⋅Z)))=((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+((Y+(X⋅Y⋅Z))⋅((X⋅Y⋅Z)+(X⋅Z))) Apply the commutative law: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+((Y+(X⋅Y⋅Z))⋅((X⋅Y⋅Z)+(X⋅Z)))=((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+((Y+(Y⋅X⋅Z))⋅((X⋅Y⋅Z)+(X⋅Z))) Apply the absorption law X+(X⋅Y)=X with X=Y and Y=X⋅Z: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+((Y+(Y⋅X⋅Z))⋅((X⋅Y⋅Z)+(X⋅Z)))=((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+((Y)⋅((X⋅Y⋅Z)+(X⋅Z))) Apply the commutative law: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅((X⋅Y⋅Z)+(X⋅Z)))=((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅((X⋅Z)+(X⋅Y⋅Z))) Apply the commutative law: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅((X⋅Z)+(X⋅Y⋅Z)))=((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅((X⋅Z)+(X⋅Z⋅Y))) Apply the absorption law X+(X⋅Y)=X with X=X⋅Z and Y=Y: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅((X⋅Z)+(X⋅Z⋅Y)))=((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅(X⋅Z)) Apply the commutative law: ((X+Y)⋅(X’+Z)⋅Z’⋅Y’)+(X⋅(Y+Z))+(Y⋅X⋅Z)=(Y’⋅(X+Y)⋅(X’+Z)⋅Z’)+(X⋅(Y+Z))+(Y⋅X⋅Z) Apply the commutative law: (Y’⋅(X+Y)⋅(X’+Z)⋅Z’)+(X⋅(Y+Z))+(Y⋅X⋅Z)=(Y’⋅(Y+X)⋅(X’+Z)⋅Z’)+(X⋅(Y+Z))+(Y⋅X⋅Z) Apply …

## You are going to create an XML document using the data below. The data is a sample of three customers of Acme Widgets. You need to create a well-formed XML document. All of the data can be placed in elements, except for the element “Title”. You must use this data as an attribute that better qualifies the person’s name. The root element name you must use is “Customers”

You are going to create an XML document using the data below. The data is a sample of three customers of Acme Widgets. You need to create a well-formed XML document. All of the data can be placed in elements, except for the element “Title”. You must use this data as an attribute that better …

## Write a recursive function that returns the number of 1 in the binary representation of N. Use the fact that this is equal to the number of 1 in the representation of N/2, plus 1, if N is odd.

Write a recursive function that returns the number of 1 in the binary representation of N. Use the fact that this is equal to the number of 1 in the representation of N/2, plus 1, if N is odd. EXPERT ANSWER #include <iostream> using namespace std; int binary_nums(unsigned int n); int main(){unsigned int n;int nums …

## Complete the following function using pass-by-reference: void findMax(int &max, int a) which assigns value ‘a’ to ‘max’ if a > max. Write a pseudo-code then implement a program in C language to find the maximum in a sequence of numbers using this function.

Complete the following function using pass-by-reference: void findMax(int &max, int a) which assigns value ‘a’ to ‘max’ if a > max. Write a pseudo-code then implement a program in C language to find the maximum in a sequence of numbers using this function. EXPERT ANSWER Pseudocode: Code: Output:

## Suppose that we would like to implement a queue system for a commercial Website Given that the website offers 3 items for sale (or a list of items), each item has a limit quantity in stock. Implement a queue of customers, each customer can buy only a few number product among the available three items. 1 – Determine the item name, their quantity in stock; 1 – Specify a queue of n customers, each customer can buy K products from one item (k is different for each customer); I – Customers take turn to enter (enqueue) and leave (dequcne) the queue acending to the 1170 xrder to purchase wanted products; 1 – If a customer successfully purchased products, then display a message and reduce the number of products in stock; otherwise, if the item has been run out, display a Warning message. Implement the above problems in C/C++ using a Queue data structur. Write a main function for testing all written functions.

EXPERT ANSWER Following is the answer to your question: Here we are taking the no of customers, quantity of the three items, customer purchase quantity as an input and as per the available and required quantity of a particular item, we are deciding if we have enough stock then we let the customer purchase otherwise …

## Assignment A simple definition for a “rect” function centered at 0 of width “W” in Matlab is rect = @(x) abs(x) <= W/2; Using the following parameters, plot d'Alambert's solution at t = {0, Δt, 2Δt, 10Δt). Use separate figures for each time step and manually fix the axis to be identical. Sample at least 100 points in space. ; 0.25 1. -1 < x < 1; p(x) = rect 2. -1 < x < 1; p(x) = rect c=1; At = 0.025 ; 9(x) = 0 C= 2; At = 0.05 ; 9(x) = 0 ;

EXPERT ANSWER ANSWER %% Matlab code. I have done this for part 1. Similarly, other parameters can be changed in the code to get answer for the question 2. w = 1; txt = {‘t = 0′,’t = \Deltat’, ‘t = 2\Deltat’, ‘t = 10\Deltat’}; dt = 0.025; t = [0 dt 2*dt 10*dt]; x …