Professional Documents
Culture Documents
3.2
Write a menu driven program that allow the user to perform any one of the following operations based
on the input given by user
i Check number is even or odd
ii Check number is positive or negative
iii Printing square of the number
iv Printing square root of the number (use math.h)
Use switch statement for a menu driven program. Also, use validation checks wherever necessary.
3.3
While travelling in a train, you observe some college students pulling the alarm chain simply to get
down at their desired point. Out of n students m<=n times students pull the chain .You have to print
according to the following:
1) If m is >=80 % of n then print strict action is required to restrict this event
2) If m is between 50 to 80 % then print guidelines should be issued
3) If between 10 to 50% then print request to restrict the event
4) If less than 10% then print No action required
FLOWCHART\ALGORITHM
ALGORITHM OF AIM1
STEP1: START
STEP2: DECLARE P,Q,N,BOYS,GIRLS,DIFF,BOYSPERCENT,GIRLPERCENT IN INT TYPE
STEP2: TAKEINPUT TOTAL NUMBER OF STUDENTS AND STORE IN N
STEP3: TAKE INPUT BOYS RATIO AND STORE IN P.
SIMILARLY GIRLS RATIO AND STORE IN Q
STEP4: CALCULATE NO OF BOYS AND GIRLS AND STORE IN BOYS, GIRLS VARIABLE
STEP5: CALCULATE BOYS AND GIRLS PERCENTAGE IN CLASS AND STORE IN BOYPERCENT
GIRLSPERCENT
STEP6: FIND DIFF IN BETWEEN IN TOTAL BOYS AND GIRLS IN CLASS AND STORE IN DIFF
VARIABLE
STEP7: PRINT BOYS,GIRLS,BOYSPERCENT,GIRLSPERCENT,DIFF
STEP8: IF DIFF>=5 OR DIFF<=-5
{ PRINT EQUAL OPPURTUNITIES}
STEP9: ELSE BOYSPERCENT>=70
{PRINT GENDER INEQUALITY}
STEP10: ELSE GIRLSPERCENT >=70
{PRINT GIRLS ARE DOMINATING IN EDUCATION}
STEP11: ELSE
{PRINT NO CONCLUSION}
STEP12: END
STEP1: START
STEP2: DECLARE VARIABLE A.
STEP3: READ THE VALUE OF A.
STEP4: IF A%2 = 0.
THE VALUE OF A IS EVEN.
ELSE THE VALUE OF A IS ODD.
STEP5: IF A>0
THE VALUE OF A IS POSITIVE.
ELSE THE VALUE OF A IS NEGATIVE.
STEP6: A*A
THE VALUE OF A AS A SQUARE.
STEP7: SQRT(A)
THE SQRT OF A.
STEP8: DISPLAY THE VALUES.
STEP9: END.
ALGORITHM FOR AIM3
STEP1:START
STEP2:DECLARE A VARIABLE n,m,percentage.
STEP3:READ THE VARIABLE.
STEP4:PERCENTAGE=m*100/N.
IF(PERCENTAGE>=80)
PRINT(STRICT ACTION IS REQUIRED)
ELSE IF(PERCENTAGE>=50 AND PERCENTAGE<=80)
PRINT(GUIDELINES SHOULD BE ISSUED)
ELSE IF(PERCENTAGE>=10 AND PERCENTAGE<=50)
PRINT(REQUEST TO RESTRICT)
ELSE IF(PERCENTAGE>10)
PRINT(ACTION IS REQUIRED)
ELSE
PRINT(ACTION IS NOT REQUIRED)
STEP5:DISPLAY THE VALUES.
STEP6:STOP.
PROGRAM CODE
1.
#include<stdio.h>
int main()
{
int n,p,q,boys,girls,diff, boyspercent, girlspercent;
printf("enter the total no. of student in class");
scanf("%d",&n);
printf("enter the ratio of boys in class");
scanf("%d",&p);
printf("enter the ratio of girls in class");
scanf("%d",&q);
boys=(p*n)/(p+q);
girls= n-boys;
boyspercent = (boys*100)/n;
girlspercent = (girls*100)/n;
return 0;
2.
#include<stdio.h>
#include<math.h>
int main()
{
int ch,a;
printf("squareroot of a is : %lf",sqrt(a));
break;
default:
printf("\n wrong input");
}
return 0;
}
3.
#include<stdio.h>
int main()
{
int n,m,percentage;
printf("enter total no. of students in train");
scanf("%d",&n);
printf("enter the no. of students who pull the chain");
scanf("%d",&m);
percentage=m*100/n;
if (m<=n)
{
if(percentage>=80)
printf("strict action is required");
else if(percentage>=50&&percentage<=80)
printf("guidelines should be issued");
else if(percentage>=10&&percentage<=50)
printf("request to restrict");
else if(percentage>10)
printf("action is not required");
}
else
printf("m is not greater than the n");
return 0;
}
ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION
(Kindly jot down the compile time errors encountered)
1. There should be no in Error in 1st program.
2. There should be no Error in 2nd program.
3. There should be no Error in 3rd program.
1. The #include pre processor directive is used to paste code of given file into current file.
it is used include system defined and user defined header files. It include file is not found
2. In the first program there will be two variable n for total no. of students in the class ,p for the
no. of boys in the class, q for the number of the girls in the class . by this variables we will find
the ratio of boys and girls in the class if the boys percent is more than or equal to 70% then it
will print the gender partially in education , if the girls percent is more than or equal to 70%
then it will print the girls are dominating in education. If both condition are not true then it
print no conclusion.
3. In the second program there will one integer variable i.e. a which is use to find the a is even or
odd, positive or negative, square and square root. And this can be done by using switch
statement.
4. In the third program there will be two variable i.e. n,m. n for the total no. of student which is
travel in train, m for the no. of student which pulls the chain there will be many condition
which is print by using switch case statement. If the condition is not true then it will print that
m is not greater than the n.
OUTPUT
2.
3.
LEARNING OUTCOMES
● Communicate effectively the basic concepts of object-oriented programming.
4. Total Marks 30