Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Department of AIT-

CSE
Institutional Training
June-July, 2021

Department of AIT-CSE

Name: PRABHU DEEP


UID: 20BCS6829
Class: IT21_AITAIML5_A
Date: 19/06/2021

Daily Worksheet - Day-3


Functions and Operator Overloading Worksheet
QUESTION-1:
Write a program which will ask the user to enter his/her marks (out of 100). Define a function that will
display grades according to the marks entered as below:
Marks Grade
91-100 AA
81-90 AB
71-80 BB
61-70 BC
51-60 CD
41-50 DD
<=40 Fail

SOLUTION:
#include<iostream>
using namespace std;

string grades(int marks )


{
if(marks<=100 && marks>=91)
{
cout<<"The grade of a student is AA.";
}
else if(marks<=90 && marks>=81)
Page 1
Department of AIT-
CSE
{
cout<<"The grade of a student is AB.";
}
else if(marks<=80 && marks>=71)
{
cout<<"The grade of a student is BB.";
}
else if(marks<=70 && marks>=61)
{
cout<<"The grade of student is BC.";
}
else if(marks<=60 && marks>=51)
{
cout<<"The grade of a student is CD.";
}
else if(marks<=50 && marks>=41)
{
cout<<"The grade of a student is DD.";
}
else if(marks<=40)
{
cout<<"The student is fail.";
}
else
{
cout<<"PLEASE GIVE A VALID INPUT";
}
}
main()
{

Page 2
Department of AIT-
CSE
int marks;
cout<<" Enter student's marks out of 100: ";
cin>>marks;
cout<<grades(marks);
return 0;
}

OUTPUT:

Page 3
Department of AIT-
CSE
QUESTION-2:
Write a program to print the circumference and area of a circle of radius entered by user by defining
your own function.

SOLUTION:
#include<iostream>
using namespace std;

float area(float radius)


{
return (3.14 * radius * radius);
}
float circum(float radius)
{
return(2 * 3.14 * radius);
}
main()
{
int radius;
cout<<"\n Enter Radius of Circle: ";
cin>>radius;
cout<<"\n Area of Circle : "<<area(radius);
cout<<"\n Circumference of Circle : "<<circum(radius);
}

OUTPUT:

Page 4
Department of AIT-
CSE

QUESTION-3:
Write a program that calculates the total point earned by a football team over a series of games and
calculate the average of team. It allows the user to enter the series of game points, then -1 to signal the
end of the list.

SOLUTION:
#include<iostream>
using namespace std;

main()
{
float average;
int score;
int total_points=0;
int total_matches=0;
cout<<"Enter the score:";
cin>>score; while(score!=-1)
{
total_matches++;
total_points+=score;
cout<<"Enter the score:";
cin>>score;
}
average=(float(total_points)/float(total_matches));
cout<<"Average points in every match of your team in this series is
"<<average<<endl;
cout<<"Total points earned by your team in this series is "<<total_points<<" in
"<<total_matches<<" matches"<<endl;
return 0;
}

Page 5
Department of AIT-
CSE
OUTPUT:

Page 6

You might also like