0% found this document useful (0 votes)
70 views4 pages

Assignment 6 and 7

The document contains two C++ programs that demonstrate the use of user-defined functions. The first program defines an average() function that calculates the average of exam scores and outputs a grade. The second program defines functions for calculating the areas of different shapes like circle, square, rectangle, and trapezium. Both programs take user input, call the appropriate functions, and output the results.

Uploaded by

Naeem Zainuudin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views4 pages

Assignment 6 and 7

The document contains two C++ programs that demonstrate the use of user-defined functions. The first program defines an average() function that calculates the average of exam scores and outputs a grade. The second program defines functions for calculating the areas of different shapes like circle, square, rectangle, and trapezium. Both programs take user input, call the appropriate functions, and output the results.

Uploaded by

Naeem Zainuudin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 6 and 7

Naeem Zainuddin 1845120

// ConsoleApplication18.cpp : This file contains the 'main' function. Program execution


begins and ends there.
//

#include "pch.h"
#include <iostream>
using namespace std;

float average(float a[], int size)


{
int i;
float avg, sum = 0;
for (i = 1; i <= size; i++)
{
sum += a[i];
}
avg = sum / size;
if ((avg <= 5) && (avg > 2.5))
{
cout << "Excellent" << endl;
}
else if ((avg <= 2.5) && (avg > 1))
{
cout << "Good" << endl;
}
else {
cout << "fail" << endl;
}

return avg;
}

int main()
{

int size, j;
cout << "Hi! This is Naeem Zainuddin Reg. No. 1845120" << endl;
cout << "Enter the length of the quizzes" << endl;
cin >> size;
float b, n[5];
for (j = 1; j <= size; j++)
{
cout << "Enter Quizzes mark " << j << " : " << endl;
cin >> n[j];
}
b = average(n, size);
cout << "Average of marks is: " << b << endl;
system("pause");
return 0;
}

// ConsoleApplication19.cpp : This file contains the 'main' function. Program execution


begins and ends there.
//

#include "pch.h"
#include <iostream>
using namespace std;

float pi, a, r, l, w, b, c, h;
float d, e, f, g;
char x;

int Circle(float pi, float r)


{
cout << "enter the value of pi" << endl;
cin >> pi;
cout << "enter the Radius of circle" << endl;
cin >> r;
cout << "Area of circle is: " << (d = (pi* r* r)) << " m^2" << endl;
return 0;
}
int Square(float a)
{
cout << "enter the value of one side length of square" << endl;
cin >> a;
cout << "Area of Square is: " << (e = (a*a)) << " m^2" << endl;
return 0;
}
int Rectangle(float l, float w)
{
cout << "enter the length of one side" << endl;
cin >> l;
cout << "enter the width of other side" << endl;
cin >> w;
cout << "Area of Rectangle is: " << (f = (l*w)) << " m^2" << endl;
return 0;
}
int Trapezium(float b, float c, float h)
{
cout << "enter the upper base" << endl;
cin >> b;
cout << "enter the lower base" << endl;
cin >> c;
cout << "enter the height of the Trapezium" << endl;
cin >> h;
cout << "Area of Trapezium is: " << (g = (((b + c) / 2)*h)) << " m^2" << endl;
return 0;
}

int main()
{
cout << "Hi! this is Naeem Zainuddin .. Reg. No. 1845120" << endl;
cout << "select Shape which you want to find their Area by using C,S,R,T" << endl;
cin >> x;
switch (x)
{
case 'c':
{
Circle(pi, r);
break;
}
case 's':
{
Square(a);
break;
}
case 'r':
{
Rectangle(l, w);
break;
}

case 't':
{
Trapezium(b, c, h);
break;
}
default:
{
cout << "error Your Shape is undefine" << endl;
break;
}
}
system("pause");
return 0;
}

a) Library Function:
The C++ Standard Library provides a rich collection of functions for performing
common mathematical calculations, string manipulations, character manipulations,
input/output, error checking and many other useful operations.

b) User Defined Function:


User-defined Function. C++ allows programmer to define their own function. A user-
defined function groups code to perform a specific task and that group of code is given a
name(identifier). When the function is invoked from any part of program, it all executes
the codes defined in the body of function

You might also like