Questions: 1 978

Answers by our Experts: 1 850

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Program that determines the class of the ship depending on its class ID.

Use logical operator

CLASS ID. SHIP CLASS

B or b BATTLESHIP

C or c. CRUISER

D or d. DESTROYER

F or f FRIGATE


The equation f(x) ≡ (1 − x) cos x − sin x = 0 has at least one root between a = 0 and

b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows:

a. It finds the midpoint r = (a + b)/2.

b. If f(r) = 0, then r is the root. If |b − a| is very small less than , then also we can

take r as the root. In either of the cases, our job is done.

c. If f(r) 6= 0 and f(a)f(r) < 0, then the root lies between a and r. We assign r to b

and go to step a.

d. If f(r) 6= 0 and f(b)f(r) < 0, then the root lies between r and b. We assign r to a

and go to step a.

e. If the number of iterations is high, we may stop the process with appropriate message.

Write the following functions with the specifications mentioned.

1. Function func takes a real number x as argument and returns the value of f(x).

2. Function cbracket takes two real numbers a and b as arguments and returns 1 if at

least one real root of f(x) lies between a and b, and 0 otherwise.


3. Function rootb that takes three real numbers a, b, eps and an integer Nmax as argu-

ments. This function returns the root of f(x) = 0 using bisection method. If the number


of iteration is more than Nmax then the function terminates with appropriate message.

Write a C program using the above functions. This program accepts a, b, eps and Nmax

from the keyboard and prints out the root


Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.


An input string is valid if:


Open brackets must be closed by the same type of brackets.

Open brackets must be closed in the correct order.


Example 1:


Input: s = "()"

Output: true


Example 2:


Input: s = "()[]{}"

Output: true


Example 3:


Input: s = "(]"

Output: false


Example 4:


Input: s = "([)]"

Output: false


Example 5:


Input: s = "{[]}"

Output: true




Please correct this program for the upper example, please don't change the way of the program which I made. you can add certain functions to solve this program if I miss anything.





#include <stdio.h>

#include <stdlib.h>


// This is where the parentheses are stored in memory

char buffer[1024];

char stack_pop();

void stack_push(char ch);

int stack_size();


int stk_sz = 0;

int str_sz;

char stack[1024];

int checker();


int main(){

FILE *fp;

  // The parentheses sequences is in the parentheses.txt file.

  fp=fopen("parentheses.txt","r");

  if(fp==NULL){

   printf("The input file does not exist.\n");

   exit(-1);

  }

  // Read the parenthese sequences into buffer array.

  fgets(buffer,1024,fp);

  //printf("%s",buffer);


//  puts(buffer);


  str_sz = strlen(buffer);


  if (checker()) {

    puts("true");

  } else puts("false");


  fclose(fp);

}


// The pop operation in the stack. To be done.

char stack_pop(){

char ch = stack[stk_sz - 1];

stk_sz--;


return ch;

}


char peek() {

  return stack[stk_sz - 1];

}


// The push operation in the stack. To be done.

void stack_push(char ch){

  stack[stk_sz] = ch;

  stk_sz++;

}



// The number of elements in the stack. To be done.

int stack_size(){

return stk_sz;

}



int checker() {

  stk_sz = 0;

  int i;

  for ( i = 0; i < str_sz; i++) {

    if (buffer[i] == '(' || buffer[i] == '{' || buffer[i] == '[') { //if there is an opening bracket

      //push it on the stack

      stack_push(buffer[i]);

    } else {

      if (stack_size() == 0) return 0; //if stack is empty, return 0


      switch (buffer[i]) {

      case ')':

        if (peek() != '(') return 0;

        stack_pop();

        break;


      case '}':

        if (peek() != '{') return 0;

        stack_pop();

        break;


      case ']':

        if (peek() != '[') return 0;

        stack_pop();

        break;

      }

    }

  }


  if (stack_size() > 0) return 0; //if stack is not empty, return 0

  return 1;

}


Create a program that calculates your daily driving cost, so that you can estimate how much money could be saved by carpooling (car-sharing), which also has other advantages such as reducing carbon emissions and reducing traffic congestion. The program should input the following information and display the user’s cost per day of driving to work:

a)     Total miles driven per day.

b)    Cost per gallon of gasoline.

c)     Average miles per gallon.

d)    Parking fees per day.

a)     Implement the following equation

 

x4 sin(45x) + x3 cos(25 x) + x2 tan(30 x) + 12x-1 +  cos(108 x2 )

 

Where value of x will be 5.


Write a Conversion program for a Shopkeeper selling following thing. First ask the user for the quantity of fruit to buy, such as 3 apples and 2 oranges. 


Make a mark sheet of a student who is enrolled in five subjects. Marks of each subject should be defined by the user. The Output should contain the percentage obtained in each subject, Total marks obtained, Total Marks and percentage attained by the student.



Write a C program that accepts a positive integer n and a real number x from the keyboard

and prints out the sum of the n terms of the series

sin(x) = X∞

n=0

tn, tn = (−1)n x

2n+1

(2n + 1)!


a)     Make a general store receipt of the customer who has bought several items. The Output should contain regular price of an item, the department code, and calculated the discount price. The receipt should be proper formatted using Escape sequence 



1.      The relationship among Database(DB), Database System(DBS) and Database Management System(DBMS) is ______.

A. DBMS includes DB and DBS                  B.DBS includes DB and DBMS

C. DB includes DBS and DBMS                  D.DB is DBS, also as DBMS

2.      In database fields, we refer SQL as _______.

A. Standard Query Language                      B. Structured Query Language

C. System Query Language                        D. Sequence Query Language

3.      Choose the proper choice to make the following query to realize:

Find the names of all customers whose street includes the substring “Main”.

                                 select customer_name

                                 from customer

                                 where customer_street  ________

A. like ‘Main\%’                                                       B. like ‘_Main_’

C. like ‘%Main%’                                                     D. like ‘\Main_’


4.      Choose the only one INCORRECT description from the followings: _____

A. Neither tuples nor attributes have order.

B. Attributes can appear in any order and the relation is still the same.

C. Each value in the database must be a member of some domain.

D. Duplicate tuples can exist in a relation.


II.       Briefly description questions. (Write your answers onto the answer sheet.) (24 marks)


1.      What are key constraints and foreign constraints?








2.      Please briefly list FOUR duties of a database administrator.








3.       Explain LEFT JOIN, OUTER JOIN and INNER JOIN.





LATEST TUTORIALS
APPROVED BY CLIENTS