You are on page 1of 7

EXPERIMENT NUMBER –3

TOPIC OF EXPERIMENT – This experiment is based on basic mathematical knowledge, C datatypes


and operators

AIM OF THE EXPERIMENT–


3.1
In a class of n students the boys to girls ratio is p:q. Find no. boys and girls in the class and print :
1)    If boys are more than or equal to 70% in the class then print gender partiality in education
2)    If difference of boys are girls is diff and in range -5<=diff<=5 then print equal opportunities of
education for both
3)    If girls are more than equal to 70% then print girls dominating in education.
4)    For all others cases print no conclusion drawn.

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

ALGORITHM FOR AIM2

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;

diff = boys - girls;


printf("number of boys in class %d", boys);
printf("number of girls in class %d", girls);
printf("the percentage of boys %d", boyspercent);
printf("the percentage of girls %d", girlspercent);
printf("the difference b/w boys and girls is %d",diff);
if (boyspercent>=70)
printf("gender partiality in education in education %d", boyspercent);
else if(diff>=-5 && diff<=5)
printf("equal oppurtunities for both boys and girls");
else if (girlspercent>=70)
printf("girls are dominating in education %d", girlspercent);
else
printf("no conclusion drawn from the given output");

return 0;

2.
#include<stdio.h>
#include<math.h>
int main()
{
int ch,a;

printf("\n enter the value of a:");


scanf("%d",&a);
printf("\n enter 1 for checking number is odd or even\n enter 2 for checking number is positive
or negative\n enter 3 for square of the number\n enter 4 for square root ");
scanf("%d",&ch);
switch (ch)
{
case 1:
if (a%2==0)
printf("\n number is even");
else
printf("\n number is odd");
break;
case 2:
if(a>0)
printf("\n number is positive");
else
printf("\n number is negative");
break;
case 3:
printf("the square of a is : %f",a*a);
break;
case 4:

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.

PROGRAMS’ EXPLANATION (in brief)

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

compiler renders error.

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.

● Demonstrate basic experimental skills for differentiating between object-oriented


and procedural programming paradigms and the advantages of object-oriented
programs.
● Demonstrate their coding skill on complex programming concepts and use it for
generating solutions for engineering and mathematical problems.

● Design the applications and real-world projects using classes, objects,


constructors, destructors, inheritance, operator overloading and polymorphism,
pointers, virtual functions, templates, exception handling, file operations and
handling.

EVALUATION COLUMN (To be filled by concerned faculty only)

Sr. No. Parameters Maximum Marks


Marks Obtained
1. Student’s performance while executing the 12
program in Computer Lab
2. Completion of worksheet with learning 10
outcomes and program’s output along with
cleanliness and discipline.
3. Clarification of theoretical concepts 8

4. Total Marks 30

5. Teacher’s Signature (with date)

You might also like