0 views

Uploaded by otherside

- Programming Meggy Jr
- c Type Casting
- Task Lib
- GreenReg Introduction
- Quiz #1
- Data Types
- NUMBER RINGS - Stevenhagen, 2017.pdf
- marilynns arduino code
- Main
- MELJUN_CORTES Statistics Program c++ Source Code
- Sample Exam Questions
- Java Basic
- Coasterbot Master 5-2-10
- Combinat or Ics
- Practice Headstrong Placement Paper December 2011
- Lunt i an Laboratory 3
- datatypes in c
- Sample Paper Amazon
- 1 A review in C
- BIBLIOGRAFÍA

You are on page 1of 4

Class: 1-B-BS(CS)

Enrollment No: 02-134191-032

LAB:08 Function-I

Exercise 1: Write a C++ Program that contains one user defined function month().

Source code:

#include<iostream>

using namespace std;

void month(int x);

int main()

{

int x;

cout<<"Enter an integer from 1 to 12 ";

cin>>x;

month(x);

return 0;

}

void month(int x)

{

if(x==1)

{

cout<<"The month is January ";

}

else if (x==2)

{

cout<<"The month is February ";

}

else if (x==3)

{

cout<<"The month is March ";

}

else if (x==4)

{

cout<<"The month is April ";

}

else if (x==5)

{

cout<<"The month is May ";

}

else if (x==6)

{

cout<<"The month is June ";

}

else if (x==7)

{

cout<<"The month is July ";

}

else if (x==8)

{

cout<<"The month is August ";

}

else if (x==9)

{

cout<<"The month is September ";

}

else if (x==10)

{

cout<<"The month is October ";

}

else if (x==11)

{

cout<<"The month is November ";

}

else if (x==12)

{

cout<<"The month is December ";

}

else

{

cout<<"default";

}

Return;

}

Output:

Exercise 2: Write a C++ Program that contains one user defined function

cal_grades().

Source code:

#include<iostream>

using namespace std;

char cal_grades(int x);

int main()

{

int x;

cout<<"Enter marks from 0-100 ";

cin>>x;

char grade = cal_grades(x);

int per=(x/100)*100;

cout<<"The grade is "<<grade;

return 0;

}

char cal_grades(int x)

{

char grade;

if(x>=85)

return 'A';

else if(x<=85 && x>=75)

return 'B';

else if(x<=75 && x>=50)

return 'C';

else if (x<50 && x>=30)

return 'D';

else

{

return 'Fail';

}

}

Output:

Exercise 3: Write a C++ Program that contains four user defined function(s)

addition(), subtraction(), division(),

multiplication().

Source code:

#include<iostream>

using namespace std;

int addition (int x, int y);

int subtraction (int x, int y);

float multiplication (float x, float y);

float division (float x, float y);

int main()

{

int a,b,c;

cout<<"Enter first number ";

cin>>a;

cout<<"Enter second number ";

cin>>b;

cout<<"Press 1 for Addition "<<endl;

cout<<"Press 2 for Subtraction "<<endl;

cout<<"Press 3 for Multiplication "<<endl;

cout<<"Press 4 for Division "<<endl;

cin>>c;

int add, sub;

float mul, div;

switch(c)

{

case 1:

add = addition (a, b);

cout<<"The sum of "<<a<<" and "<<b<<" is "<<add;

break;

case 2:

sub = subtraction (a, b);

cout<<"The difference of "<<a<<" and "<<b<<" is "<<sub;

break;

case 3:

mul = multiplication (a, b);

cout<<"Product of "<<a<<" and "<<b<<" is "<<mul;

break;

case 4:

div = division (a, b);

cout<<"Division of "<<a<<" and "<<b<<" is "<<div;

break;

default:

cout<<"Enter two integers ";

break;

}

return 0;

}

int addition (int x, int y)

{

return (x+y);

}

int subtraction (int x, int y)

{

return (x-y);

}

float multiplication (float x, float y)

{

return (x*y);

}

float division (float x, float y)

{

return (x/y);

}

Output:

- Programming Meggy JrUploaded bylatec
- c Type CastingUploaded byQuello Della Porta Accanto
- Task LibUploaded byKiran Gunasegaran
- GreenReg IntroductionUploaded bymarkfoodyburton
- Quiz #1Uploaded byhadukenryu9761
- Data TypesUploaded byKarthi Keyan Veera
- NUMBER RINGS - Stevenhagen, 2017.pdfUploaded byrubenvic
- marilynns arduino codeUploaded byapi-296708165
- MELJUN_CORTES Statistics Program c++ Source CodeUploaded byMELJUN CORTES, MBA,MPA
- MainUploaded byrmccloskey8
- Sample Exam QuestionsUploaded bygirmay tadese
- Java BasicUploaded byAshok Kumar
- Combinat or IcsUploaded byshubham jha
- Coasterbot Master 5-2-10Uploaded byblackdogrobotics
- Practice Headstrong Placement Paper December 2011Uploaded byAta Ur Rahman Khalid
- Lunt i an Laboratory 3Uploaded bygui9871
- datatypes in cUploaded byDeepanshuGabba
- Sample Paper AmazonUploaded byAnkit Mittal
- 1 A review in CUploaded byFay Fernandez-Cantuangco
- BIBLIOGRAFÍAUploaded byRafael Fonseca Martinez
- Unboxing and Autoboxing in JavaUploaded byKanchan Mahajan
- CNotesUnit3Uploaded byJayagowri Cheluri
- 14.docxUploaded bysharmapankaj0
- NioUploaded byAsier Sanz Espeso
- Java Pgm20Uploaded byRavi Prakash Verma
- to 10Uploaded byeroze_heart
- Diabtes DectationUploaded bydivyashishtomar
- Helen i Proxy LogUploaded byaslam
- Casting in JavaUploaded byMary James
- module 5 topic e- grade 4Uploaded byapi-330738410

- 6 1 PercentsUploaded byapi-25931785
- Centurion Rules.pdfUploaded byDavid Cassidy
- 3PUT_2014Uploaded byAmardeep Singh
- Chapter 1-Whole NumbersUploaded byRyan N H. Ko
- rajesh-verma-math.pdfUploaded byapoorva jain
- (A Collection of Programming Interview Questions 3) Dr Antonio Gulli-A Collection of Bit Programming Interview Questions solved in C++-CreateSpace Independent Publishing Platform (2014)Uploaded byapatra01714
- Fundamental Classes 2Uploaded byrahul rastogi
- 927 24635589.NZL H Directed Numbers NZLUploaded byChyrsella Verena
- CN3.pdfUploaded bysbfjbsjkbf
- Skills no 9Uploaded byarn_sms
- III_Maths-Worksheets_Session_2012_2013.pdf- 2 no.pdfUploaded byPintu Parmanik
- Number Systeam ConversionUploaded byUday Shubhraj
- Article 1 Binary NumbersUploaded bymhussain
- Maths TricksUploaded byBHAVNA FATEHCHANDANI
- Use Mathematical Concept and TechniquesUploaded byvillamor niez
- BCD to 7Segement Design Lecture NotesUploaded byraul gironella
- DPSD unit 1Uploaded byDharma Raj Kavitha
- Design of a Vedic Arithmetic and Logical Unit using LabViewUploaded byIJIRST
- ArithmeticUploaded byPaula Nelida Brito
- An Introduction to FractionsUploaded byalane.tentoni
- Lesson Plan- sample lesson planUploaded byFuertes Lyn-dlr
- Reliable Two-Dimensional Graphing Methods for Mathematical Formulae with Two Free VariablesUploaded bySoyoko U.
- Answer Key for Fraction Worksheet 1 Std 3Uploaded byRachel Lim
- COMPUTER HOMEWORK 11.docUploaded byAnonymous dpcoL6
- Benefits of the Abacus Edited FullUploaded bySca Jalpaiguri
- GMAT Math StrategiesUploaded byLuis Zamora
- Jntu Anan Ece 2 2 Stld Set 1Uploaded byRushiram Reddy
- Unit-1 Real Numbers CoreUploaded byChandra Sekhar
- Math Unit CCUploaded bymichelleheller6
- Euler - Continuous FractionsUploaded bylucaspunky