0% found this document useful (0 votes)
65 views17 pages

Programs 150221235044 Conversion Gate01

The document contains code snippets demonstrating different C++ programming concepts including structures, pointers, functions, arrays of structures, and parameters. Some key examples include: 1) Defining and using a student structure with name and roll number fields, and creating an array of structures to store multiple student records. 2) Passing arguments to functions by reference and by value, and returning values from functions. 3) Demonstrating nested structures by defining nested info and book structures. 4) Defining arrays of structures to store and display records for multiple students. So in summary, the document provides examples of common C++ programming concepts like structures, functions, and arrays through short code snippets.

Uploaded by

Ahmed Elsayed
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)
65 views17 pages

Programs 150221235044 Conversion Gate01

The document contains code snippets demonstrating different C++ programming concepts including structures, pointers, functions, arrays of structures, and parameters. Some key examples include: 1) Defining and using a student structure with name and roll number fields, and creating an array of structures to store multiple student records. 2) Passing arguments to functions by reference and by value, and returning values from functions. 3) Demonstrating nested structures by defining nested info and book structures. 4) Defining arrays of structures to store and display records for multiple students. So in summary, the document provides examples of common C++ programming concepts like structures, functions, and arrays through short code snippets.

Uploaded by

Ahmed Elsayed
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/ 17

Programs:-

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

struct student
{
char Name[20];

int Rollno;
};
student s[5];
void main()
{
int i;

for(i=0;i<=4;i++)
{
cout<<"Enter Name:";
cin.getline(s[1].Name,20);
cout<<"Enter Rollno :";
cin>>s[i].Rollno;
cout<<endl;
}
for(i=0;i<=4;i++)
{

cout<<"Your Name is :"<<s[i].Name<<endl;


cout<<endl;
cout<<"Your Roll No is :"<<s[i].Rollno<<endl;
cout<<endl;
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],i,max;
for(i=0;i<10;i++)
{
cout<<"Enter a value:";
cin>>a[i];
}
max=a[0];
for(i=0;i<10;i++)
if(max<a[i])
max=a[i];
cout<<"Maximum Value :"<<max<<endl;

getch();
}
#include<iostream.h>
#include<conio.h>
void abc();
struct info
{
int rollno;
int age;
};
struct book
{
int pages;
int price;
};
info in;
book b;
void main()
{
cout<<endl;
cout<<"\t\t....Your Nested Structure Programming...."<<endl;
cout<<endl;
cout<<endl;
cout<<"Enter Your Roll no :";
cin>>in.rollno;
cout<<"Enter Your Book pages:";
cin>>b.pages;
cout<<"Enter your Age:";
cin>>in.age;
cout<<"Enter Your Book Price:";
cin>>b.price;

cout<<endl;
cout<<endl;
cout<<"your Roll no:"<<in.rollno<<endl;
cout<<"Your Book Pages:"<<b.pages<<endl;
cout<<"Your Age :"<<in.age<<endl;
cout<<"Your Price:"<<b.price<<endl;

getch();
}

Pointers:-
#include<iostream.h>
#include<conio.h>
void abc(int &);
void abc(int &a)
{
int m;
cout<<"Enter A Value:";
cin>>m;
cout<<"Your pass "<<a<<endl;
a=a+m;
// cout<<"The value is:"<<a<<endl;
}
void main()
{
int v_actual;
cout<<"Enter a value:";
cin>>v_actual;
cout<<"your actual value is:"<<v_actual<<endl;
abc(v_actual);
cout<<"Your value:"<<v_actual<<endl;
getch();
}
Structure:-
#include<iostream.h>
#include<conio.h>

struct student
{
char Name[30];
char Fname[30];
int Rollno;
};
student s;
void main()
{

cout<<"Enter Name :";


cin>>s.Name;
cout<<endl;
cout<<"Enter Father Name :";
cin>>s.Fname;
cout<<endl;
cout<<"Enter Rollno :";
cin>>s.Rollno;
cout<<endl;

cout<<endl;
cout<<endl;
cout<<endl;

cout<<"Your Name is :"<<s.Name<<endl;


cout<<endl;
cout<<"Your Father Name is :"<<s.Fname<<endl;
cout<<endl;
cout<<"Your Roll No is :"<<s.Rollno<<endl;

getch();
}
Function and structure:-
#include<iostream.h>
#include<conio.h>
void abc();
struct info
{
int rollno;
int age;
};
info s;
void main()
{
for(int i=0;i<=5;i++)
{
abc();
}
getch();
}

void abc()
{
cout<<"Enter a rollno:";
cin>>s.rollno;

cout<<s.rollno<<endl;

}
Arrays of Structure:-
#include<iostream.h>
#include<conio.h>

struct student
{
char Name[30];
char Fname[30];
int Rollno;
};
student s[5];
void main()
{
for(int i=0;i<=5;i++)
{
cout<<"Enter Name :";
cin.getline(s[i].Name,30);
cout<<endl;
cout<<"Enter Father Name :";
cin.getline(s[i].Fname,30);
cout<<endl;
}
for(i=0;i<=5;i++)
{
cout<<"Enter Rollno :";
cin>>s[i].Rollno;
cout<<endl;
}
cout<<endl;
cout<<endl;
cout<<endl;

for(i=0;i<=5;i++)
{
cout<<"Your Name is :"<<s[i].Name<<endl;
cout<<endl;
cout<<"Your Father Name is :"<<s[i].Fname<<endl;
cout<<endl;
}
for(i=0;i<=5;i++)
{
cout<<"Your Roll No is :"<<s[i].Rollno<<endl;
}
getch();
}
Function:-
#include<iostream.h> //header files
#include<conio.h>

void function(); // function declaration...


int c; //Global variable declaration..
void function() //function starting point..
{
int a,b;
cout<<"Enter a number:";
cin>>a;
cout<<"Enter b number:";
cin>>b;
c=a+b;
}

void main()
{
function(); //function call...
cout<<c<<endl;

getch();
}
Function with return value:-
#include<iostream.h> //header files
#include<conio.h>

int function(); // function declaration...

int function() //function starting point..


{
int a,b;
cout<<"Enter a number:";
cin>>a;
cout<<"Enter b number:";
cin>>b;

return a*b;
}

int main()
{
int x=0; //Local declaration of variable.....
x=function();
cout<<"Your return value in function is:"<<x<<endl;

return 0;
}

Parameters:-
#include<iostream.h>
#include<conio.h>

void getdata(int a);


void getdata(int a)
{
int b;
cout<<"The value which is pass is as:"<<a;
b=a*a;

cout<<"The value of b is :"<<b<<endl;


}
void main(){
int x;
cout<<"Enter a number :";
cin>>x;

getdata(x);

cout<<"The value of is as :"<<x<<endl;


getch();
}
Return Function with Parameter:-
#include<iostream.h> //header files
#include<conio.h>

int function(int a,int b); // function declaration with


Parameter...

int function(int a,int b) //function starting point..


{
int ans=a+b;

return ans;
}

void main()
{

int a,b;
cout<<"Enter a vlue:";
cin>>a;
cout<<"Enter b value:";
cin>>b;
cout<<function(a,b)<<endl;
getch();
}
return with parameter:-
#include<iostream.h>
#include<conio.h>

int abc(int,int);
int abc(int a, int b){
int m;
m*m;
cout<<"The value of m is:"<<m;

return m*m;

}
void main()
{
int x;
x=abc(x,x);
cout<<"The value returned by function" <<x;
getch();
}

You might also like