0% found this document useful (0 votes)
16 views

Assignment 2

The document provides instructions for an assignment on conditional and branch statements in C programming. Students are instructed to [1] create a directory called "Lab-2" to store assignment programs, [2] name each program file "<p>.c" where <p> is the problem number, and [3] submit all files by 5:15PM with penalties for late submission. The assignment then lists out 4 problems to solve involving conditional statements, switch statements, and ternary operators. Sample inputs and outputs are provided for each problem.

Uploaded by

akshat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment 2

The document provides instructions for an assignment on conditional and branch statements in C programming. Students are instructed to [1] create a directory called "Lab-2" to store assignment programs, [2] name each program file "<p>.c" where <p> is the problem number, and [3] submit all files by 5:15PM with penalties for late submission. The assignment then lists out 4 problems to solve involving conditional statements, switch statements, and ternary operators. Sample inputs and outputs are provided for each problem.

Uploaded by

akshat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PDS Lab, Section – 18 , Date: 29th Aug 2023

Assignment – 2 [Conditional and branch statements,


Switch, Ternary operators]
-------------------------------------------------------------------------------------------------------------------------------
Instructions
-------------------------------------------------------------------------------------------------------------------------------

1. Create a directory named as Lab-2.


2. Give the name of the program as <p>.c where <p> implies the problem number,
like 1.c, 2.c, 3.c, etc. Store all the programs of this week under this directory.
3. You should upload all .c files (1.c, 2.c, 3.c ....) to the Moodle course web page
latest by 5.00 PM (without penalty). The cutoff time will be till 5.15 PM with a
penalty of 25% on your secured marks (i.e., if you secured 80 marks, after
penalty you will get 60 marks). Beyond 5.15 PM, the moodle system will not allow
you to submit, as a result you will get zero.

---------------------------------------------------------------------------------------------------------------------

1) Write a C program that will take co-ordinates of three points A(x1, y1), B(x2, y2) and C(x3,
y3) from the user through keyboard. Assume that all the co-ordinates are integers. Check,
whether the three points are collinear or not. If they are not collinear, then name the triangle
they form (equilateral/isosceles/scalene/right-angle). (20M)

Example1:
Input:
A = (1 1)
B = (3 3)
C = (7 7)
The given points A, B, C are collinear.

Example2:
Input:
A = (1 2)
B = (3 4)
C = (5 6)
The given points A, B, C are not collinear.
They form isosceles rightangle triangle.

2) Read three real numbers, i.e., a, b, and c, which represent the coefficients of a quadratic
equation and display them in the exact form ax^2 + bx + c = 0. Hence check whether the
roots are real, coincident, or complex according to the rules of quadratic equation and
display it. No need to find out the roots separately. Additionally if the roots are complex,
determine the quadrant (i.e 1 st quadrant/2 nd quadrant/3 rd quadrant/4 th quadrant) of the
2D Argand plane in which the first complex root of the form a + ib lies. Note that complex
roots occur as conjugate pairs a+ib and a−ib, consider only the root in the form a+ib and
determine in which quadrant it lies. (20M)

Example1: (Please take the input and display the output as shown)
Input:
a:5
b:2
c:1
Output:
Equation: 5xˆ2 + 2x + 1 = 0
Roots: Complex
Quadrant of 1st complex root: 2nd [Reason: The first complex root is −0.2 + 0.4i as per
the given example, hence it lies in the 2nd quadrant]

Example2: (Please take the input and display the output as shown)
Input:
a:1
b:2
c:-3
Output:
Equation: xˆ2 + 2x − 3 = 0
Roots: Real

3) Take input from the keyboard the marks obtained by a student in Physics, English and
Sociology respectively and find out the highest among the three. Display the grade of the
student corresponding to the highest scoring subject, where grade = 'A' if the marks in the
highest subject >80%, grade = 'B' if the marks is between 60% to 80% and grade = 'C', if the
marks is less than 60%. Assume full marks to be 100. (Use Ternary operator to solve this
problem) (30M)
Example1:
Input:
Marks in Physics = 78
Marks in English = 92
Marks in Socialogy = 64

Output:
Grade in English = ‘A’

Example1:
Input:
Marks in Physics = 59
Marks in English = 52
Marks in Socialogy = 45

Output:
Grade in Sociology = ‘C’

4) Write a C program to display the salary of IITKGP’s employee based on his nature of job
(faculty, administrative staff and technical staff), designation and years of experience. The
inputs to be given to the program are Employee type, Designation, Basic and years of
experience. You may need to use switch statements (2-level) to solve this problem. Display
the input data as well as output in proper format. (30M)

Employee (type) Designation (code) Basic Pay

Faculty (‘F’ or ‘f’) Assistant Professor (1) Basic

Associate Professor (2) Basic × 1.5

Professor (3) Basic × 2

Administrative Staff (‘A’ or ‘a’) Assistant Registrar (1) Basic × 0.5

Deputy Registrar (2) Basic × 0.8

Registrar (3) Basic × 1.2

Technical Staff (‘T’ or ‘t’) Lab Technician (1) Basic × 0.35

System Analyst (2) Basic × 0.75

Chief System Analyst (3) Basic × 1.25

Additional Increment (AI) = 0.1 × Basic Pay × years

Total Pay = Basic Pay + AI

Example:
Input:
Employ type = ‘a’
Designation = 2
Basic = 1,00,000
Experience = 5

Output:
Salary of Deputy Registrar = 1,20,000

You might also like