Tuesday, 21 February 2017

Grade The Steel

QUESTION DESCRIPTION : 

A certain grade of steel is graded according to the following conditions.

Hardness must be greater than 50.
Carbon content must be less than 0.7.
Tensile strength must be greater than 5600.
The grades are as follows:

Grade is 10 if all three conditions are met.

Grade is 9 if conditions (i) and (ii) are met.
Grade is 8 if conditions (ii) and (iii) are met.
Grade is 7 if conditions (i) and (iii) are met.
Grade is 6 if only one condition is met.
Grade is 5 if none of three conditions are met.
Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel. 


TEST CASE 1

INPUT

2
53 0.7 5602
55 0 5499

OUTPUT

Grade 10
Grade 9


EXPLANATION :

The code is a basic decision making question , requiring to use if and else ifControl Statements ). The first input is the number of test cases that the user will input. Then there will be a set of three inputs referring to the values hardness, carbon content  and tensile strength respectively. We have to check the values under different conditions and rate the steel under different grades from 1 to 10 .


ALGORITHM :

  • Input the number of test cases from the user ( t )
  • Run loop from 0 to the number of test cases ( i<t )
  • Input the values of hardness, carbon content and tensile strength ( hs,cc,ts )
  • Check for grade 10 ( hs>=50&&cc<=0.700000000&&ts>=5600 )
  • Check for grade 9 ( hs>=50&&cc<=0.7 )
  • Check for grade 8 ( cc<=0.7&&ts>=5600 )
  • Check for grade 7 ( hs>=50&&ts>=5600 )
  • Check for grade 6 ( hs>=50||cc<=0.7||ts>=5600 )
  • If all the conditions are false then it is grade 5
  • Print the grade with required message
  • Redo this for all other test cases 

SOLUTION : (Please use this as reference only)

CODE


 

No comments:

Post a Comment