CSL101 Assignment 3 Solved

35.00 $

Category:

Description

Rate this product

1 Consider an employee details are being stored through a C structure that contains the name of the employee, his/her employee ID and the salary. Write a C program that prints the employee names whose salary is less than a target salary (user input).

Q.2   Define a structure named census with the following three members:

  1. A character array city [ ] to store the city name
  2. An integer to store the population of the city
  3. A float member to store the literacy level Write a program to do the following:
  4. To read the details of 5 cities using an array of structures.
  5. To sort the records based on literacy level and display.

Q.3 Write a C program to create a menu driven program (using switch case) that depicts the working of a library. Create a structure called library to hold the accession number, title of the book, author name, price of the book, and flag indicating whether book is issued or not. Write the functions to:

  1. Add book information
  2. Display all books information
  3. List all books of given author
  4. List the count of books currently available in the library of the given title.
  5. Exit

 

Note: Google might help you to understand menu driven program.

  • Define a structure to store the name, an array marks [ ] which stores the marks of five different subjects and a character grade. Write a program to read and display the details of the student whose name is entered by the user.
  • Modify Q.4 to print each student’s average marks, subject-wise class average (that includes average of all the students’ marks).
  • Given the details of n employees (employee name and salary), write a C program which sorts the employee names according to the length (no of characters) of their names. If the lengths of employee names are same, then break the tie by alphabetical order. Finally, display the details of employees in the above mentioned order. You are free to use library functions under “string.h”.
  • Define a structure that can describe a point in 2-D. A circle in 2D can be specified by its centre (a point) and radius. Define a structure that can describe a circle in 2D. Write a C function that does the following. It accepts a circle and a point as arguments. It returns 1 if the point lies inside the circle but returns 0 otherwise.

 

  • Construct a structure variable pt which represents a point in Cartesian xy-plane. Using pt, construct a structure variable tri which represents a triangle in the xy-plane. Write a C function which accepts a triangle as argument and returns the perimeter of the triangle. Pick the endpoints of each side and calculate, d =

√(x1 − x2)2 + (y1 − y2)2 The distance between those endpoints gives you the length of that side. When you have the lengths of all three sides, add them together to get the perimeter. Write the separate function to calculate the distance d between two co-ordinates.

  • A polynomial can be represented in a structure with the following members:
  1. a float array to store the coefficients
  2. an integer to store the degree of the polynomial (highest power in polynomial)

 

For example, a polynomial 2.3 x4 – 4x + 1.6 has degree, d = 4 and coefficients are {2.3, 0, 0, -4, 1.6} to be stored in an array. The missing term’s coefficients are denoted by zero in this array. Represent this structure in C language.

 

  • Write a function to read and store the polynomial using structure defined above.

This function should return the polynomial read.

  • Write a function to add two polynomials p and q represented in the same structure. Assume both p and q have same degree.
  • Write a function which takes as parameters a polynomial and value of x and evaluates the polynomial using Horner’s rule: a0 x0 + a1 x1 + a2 x2 + a3 x3 + a4 x4 = a0 + x (a1 + x (a2 + x (a3 + x (a4)))) and so on. The function should return the result calculated from the right hand side expression.

Q.10 Create a database of (at least 5) students using structures, where in each entry of the database will have the following fields:

 

  1. a name, which is a string with at most 128 characters
  2. their marks in physics which is an int between 0 and 100
  3. their marks in chemistry which is an int number between 0 and 100 4. their marks in mathematics which is an int number between 0 and 100

You have to output a list of students in the following order.

  1. if a student ‘A’ has lower marks in physics than a student ‘B’, then A’s data is listed before B.
  2. If A and B have the same physics marks and A has lower chemistry marks than B, then A is listed before B.
  3. If A and B have the same marks in physics and chemistry, and A has lower marks in mathematics than B, then A is listed before B.
  4. If all marks are equal and A’s name precedes B’s name in the dictionary order, then A is listed before B.

 

Note: You are free to use library functions under “string.h”. Maintain the separate function to sort/decide ordering.

 

  • CP_Assignment_3-m4nkgl.zip