Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Saturday, 4 March 2017

C++ program of template

In this program we will clear the concept of template in c++

//Code starts 

#include<iostream>
#include<conio.h>

using namespace std;

template <class T>

void abc(T* array,int size)
{
for(int i=0;i<size;i++)
{
cout<<array[i]<<",";
}
}

int main()
{
float ar[5]= {0.3,2.5,6.3,5.9,6.6};

int arr[5];


for(int i=0;i<5;i++)
{
cout<<"Enter integer : ";
cin>>arr[i];
}

abc(ar,5);
cout<<endl;
abc(arr,5);

getch();

}
//Code ends

OUTPUT:


Share:

Saturday, 18 February 2017

C++ program of entering employee data through functions and structure

In this program we will learn how to enter employee data through functions using structure.
The code is given below.

//code starts
#include <iostream>
#include <conio.h>

using namespace std;

struct emp
{
int id,salary;
char name[20];
};

void input (emp &emp1);

void show (emp emp1);

int main()
{
emp emp1;

input (emp1);

show (emp1);

     getch();

}

void input (emp &emp1)
{
cout<<"Enter Employee ID : "<<endl;
cin>>emp1.id;

cout<<"Employee Name : "<<endl;
cin>>emp1.name;

cout<<"Enter Salary :"<<endl;
cin>>emp1.salary;
}

void show (emp emp1)
{

cout<<"ID: "<<emp1.id<<endl;

cout<<"Name: "<<emp1.name<<endl;

cout<<"Salary: "<<emp1.salary;
}
//code ends


Share:

C+ program, Functions of exponential, increment and addition

#include <iostream>
#include <conio.h>

using namespace std;

int expo(int a, int b);

int inc(int x);

int add(int a, int b);

int main()

{
int num,x;
cout<<"Enter Number for exponential"<<endl;
cin>>num;
cout<<"Enter Power of exponential"<<endl;
cin>>x;
cout<< "Exponential of " <<num<<" is "<<expo(num,x)<<endl;
cout<<"Increament of "<<x<<" is "<<inc(x)<<endl;
cout << "Addition of "<<num<<" and "<<x<<" is "<< add(num,x);
getch();
}

int add(int a, int b)

{
int ans=0;
ans=a+b;
return ans;
}


int inc(int x)

{
x=x+1;
return x;
}



int expo(int a, int b)
{
int ans=1;
for(int i=1;i<=b;i++)
{
ans=ans*a;
}
return ans;
}



Share:

Sunday, 12 June 2016

C++ Program of Exponential using Functions

In this program we will learn how to take exponential of a variable e.g 10^2.
The code is given below.

//Code starts
#include<iostream>
#include<conio.h>

using namespace std;

int expo(int b, int p)
{
 int temp=1;        //taking a temporary variable

 for(int i=1; i<=p; i++) //for loop starts
 {
  temp=temp*b;
 }

 return temp;  //returning value of temporary variable
}


int main()   //main starts

{

 int c,d;

 cout<<"Enter Base to Find its Exponential : ";
 cin>>c;

 cout<<"Enter Power to Find its Exponential : ";
 cin>>d;

 cout<<"Answer = "<<expo(c,d); // Function calling
getch();
}
//Code ends
OUTPUT:



Share: