Question

In: Computer Science

1.Write a new expression similar to the following :     E1= a+b*c+(d*e+f)*g a)Convert your expression to...

1.Write a new expression similar to the following :

    E1= a+b*c+(d*e+f)*g

a)Convert your expression to postfix form.

b) Trace the algorithm Postfix on slide 38 using your expression.

2.Write a new expression similar to the following :

   E2= 6*((5+(2+3)*8)+3)

  1. Convert your expression to postfix form.
  2. Trace EvalPostfix algorithm on slide 53 using your expression.

    3.Write a program that receives some input values and

        a ) Displays these values by pointers, c)Displays their memory addresses.

Solutions

Expert Solution

1)  E1= a+b*c+(d*e+f)*g

a) Postfix form:

  abc*+de*f+g*+

b)

Symbol Postfix String Stack
a a
+ a +
b ab +
* ab +*
c abc +*
+ abc*+ +
( abc*+ +(
d abc*+d +(
* abc*+d +(*
e abc*+de +(*
+ abc*+de* +(+
f abc*+de*f +(+
) abc*+de*f+ +
* abc*+de*f+ +*
g abc*+de*f+g +*
abc*+de*f+g*+

2) E2= 6*((5+(2+3)*8)+3)

a) Postfix form:

6523+8*+3+*

b)

Symbol Postfix expression Stack
6 6
* 6 *
( 6 *(
( 6 *((
5 65 *((
+ 65 *((+
( 65 *((+(
2 652 *((+(
+ 652 *((+(+
3 6523 *((+(+
) 6523+ *((+
* 6523+ *((+*
8 6523+8 *((+*
) 6523+8*+ *(
+ 6523+8*+ *(+
3 6523+8*+3 *(+
) 6523+8*+3+ *
6523+8*+3+*

3)

//Program:

#include<stdio.h>
int main()
{
   int x, y; //declaring variables of integer type
   int *a, *b; //declaring pointers of integer type
   printf("Enter x: ");
   scanf("%d",&x); //Taking input from user
   printf("\nEnter y: ");
   scanf("%d",&y); //Taking input from user
   /*assigning pointers to variable*/
   a=&x;   
   b=&y;
   printf("\nValue of x: %d", *a); //printing value of x through pointer a
   printf("\nValue of y: %d", *b); //printing value of y through pointer b
   printf("\nMemory address of x: %p", a); //printing memory address of x
   printf("\nMemory address of y: %p", b); //printing memory address of y
   return 0;
}

//Output:


Related Solutions

(a) (f ∘ g)(3) (b) g(f(2)) (c) g(f(5)) (d) (f ∘ g)(−3) (e) (g ∘ f)(−1) (f) f(g(−1))
(a)    (f ∘ g)(3) (b)    g(f(2)) (c)    g(f(5)) (d)    (f ∘ g)(−3) (e)    (g ∘ f)(−1) (f)    f(g(−1))  
If there are 7 total notes C, D, E, F, G, A, and B and if...
If there are 7 total notes C, D, E, F, G, A, and B and if a five-note melody is selected at random (so that all melodies counted in part (a) are equally likely to be chosen), what is the probability that the melody will include exactly two “A” notes, but no other repeated notes? (A few allowable examples: AACEG, ACAEG, DFACA, EAABC, etc.)
Assume chromosome 1 has the following structure: A B centromere C D E F G What...
Assume chromosome 1 has the following structure: A B centromere C D E F G What could be the result of a pericentric inversion? Where should the chromosome break to obtain this aberration?
Given the following knowledge base: a <- b^c. b <- d^e. b <- g^e. c <-...
Given the following knowledge base: a <- b^c. b <- d^e. b <- g^e. c <- e. d. e. ƒ <- a^g. Which of the following would be the trace of resolved atoms assuming a bottoms-up proof procedure? Select one: a. {a,b,c,e,g} b. {a,b,c,e,d} c. {g,e,b,e,c,a} d. None of these options Constraint Satisfaction Problem (CSP) is consists of a set of _________________. Select one: a. Variables, heuristics, and solutions b. Variables, domains, and backtracking c. Variables, domains, and constraints d....
Seven people (A,B,C,D,E, F, and G) are seated in a row. Suppose A,B, and C are...
Seven people (A,B,C,D,E, F, and G) are seated in a row. Suppose A,B, and C are freshmen, D and E are sophomores and F and G are juniors. How many arrangements are possible if: (a) D and F must sit together? (b) A and C must not sit together? (c) All freshmen must sit together? (d) All freshmen must sit together, all sophomores must sit together, and all juniors must sit together? (e) Exactly two people sit between A and...
A restaurant has dishes A, B, C, D, E, F and G The owners anticipate that...
A restaurant has dishes A, B, C, D, E, F and G The owners anticipate that dishes will be ordered in the following proportions: 30% (A), 15% (B), 20% (C), 5% (D), 8% (E), 12% (F) and 10% (G). The number of orders placed during the first two days of business was 75 (A), 60 (B), 50 (C), 14 (D), 20 (E), 40 (F), and 41 (G).    State and conduct the appropriate hypothesis test to determine whether there is...
Consider the relation R= {A, B, C, D, E, F, G, H} and the set of...
Consider the relation R= {A, B, C, D, E, F, G, H} and the set of functional dependencies: FD= {{B}—> {A}, {G}—> {D, H}, {C, H}—> {E}, {B, D}—> {F}, {D}—>{C}, {C}—> {G}} 1) Draw FD using the diagrammatic notation. 2) What are all candidate keys for R? 3) If delete {C}—>{G} and change {C, H}—> {E} to {C, H}—> {E, G}, what are all candidate keys for R
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables and display the resulting value.
Consider the following bivariate data. Point A B C D E F G H I J...
Consider the following bivariate data. Point A B C D E F G H I J x 0 1 1 2 3 4 5 6 6 7 y 5 5 6 5 4 3 2 0 1 1 (a) Construct a scatter diagram of the given bivariate data. (Do this on paper. Your instructor may ask you to turn in this work.) (b) Calculate the covariance. (Give your answer correct to two decimal places.) (c) Calculate sx and sy. (Give...
Consider the following demand curve: A B C D E F G H I J P...
Consider the following demand curve: A B C D E F G H I J P $0.50 $0.45 $0.40 $0.35 $0.30 $0.25 $0.20 $0.15 $0.10 $0.05 QD 1 2 4 6 9 12 16 20 25 30 Calculate elasticities for pairs of points to check statements that were made during class and in the text. When making the calculations, use average price and average quantity for the two points. The formula for this should be in your notes. It is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT