Recent

Comments

Follow us on Facebook

Sunday 31 December 2017

Define a structure student , first function takes the values and pass it to the second function as an argument to display them

- No comments

Image result for c++


#include <iostream>
using namespace std;
struct student
{


char name [100];
int rollno;
};
student value(student);
void dispalydata(student);
main()
{
student v;
   v=value(v);
   dispalydata(v);
}
student value(student s)
{


cout<<"enter your Good name ";
cin.get(s.name,100);
cout<<"enter your roll no  ";
cin>>s.rollno;
return s;


}
void dispalydata(student s)
{
cout<<"\nfollowing is your information   ";
cout<<"\nNAME"<<"   "<<s.name<<endl;
cout<<"\nROLL NO"<<"   "<<s.rollno<<endl;

}

Define a structure student and take values of the members in main and pass the structure to the function as an agrument to display the values

- No comments

Image result for c++ structure

 pass the structure to the function as an agrument to display the values

#include <iostream>
using namespace std;
struct student
{


char name [30];
string  field;
string  semester;
int rollno;
};
void dispalydata(student);
main()
{
student s;

cout<<"enter your Good name ";
cin.get(s.name,100);
cout<<"which is your field  ";
    cin>>s.field;
cout<<"enter your roll no  ";
cin>>s.rollno;

cout<<"In which semeter you study  ";
cin>>s.semester;

dispalydata(s);
return 0;

}
void dispalydata(student s)
{
cout<<"\nfollowing is your information   ";
cout<<"\nNAME"<<"    "<<s.name<<endl;
cout<<"ROLL NO"<<"    "<<s.rollno<<endl;
cout<<"FEILD"<<"   "<<s.field<<endl;
cout<<"semester"<<"    "<<s.semester<<endl;

}

Sunday 24 December 2017

1. Write a function that is called by function main () and receives five integers. The function should print the sum of five integers and return the average to main. The average is printed in main.

- No comments
#include <iostream>
using namespace std;
main()
{
int avg (int,int,int,int,int);
int a,b,c,d,e,z;
cout<<"\nenter the five number for sum and avg  ";
cin>>a>>b>>c>>d>>e;
z=avg(a,b,c,d,e);
cout<<"\nthe avg of five number is   =      "<<z;

}
int avg (int s,int t,int u,int v,int r)
{
int sum,avg;
sum=s+t+u+v+r;

avg=sum/5;
    cout<<"\nsum is     =         "<<sum;
return avg;
}

Tuesday 19 December 2017

write a program to add,update,delete and quit the menu of an array using function in c++

- No comments
#include <iostream>
using namespace std;

int add(int a[]);
int update(int a[]);
int delet(int a[]);

int main()
{
int arr[5]={0},ss,a,b,c,d,QUIT_CHOICE=4;
cout<<"OPTIONS: "<<endl<<endl;
ii:
cout<<endl<<endl<<"press 1 for adding."<<endl;
cout<<"press 2 for updating value."<<endl;
cout<<"press 3 for deleting value."<<endl;
cout<<"press 4 for quit the program"<<endl;
cout<<"select option.";
cin>>ss;
if (ss != QUIT_CHOICE)
{
 
switch(ss)
{
case 1:
add(arr);
break;

case 2:
b=update(arr);
break;

case 3:
c=delet(arr);
break;



}

     
cout<<"array elements are:";
for(int i=0; i<5; i++)
{
cout<<arr[i]<<"\t";
}
goto ii;
while (ss != QUIT_CHOICE);
         return 0;

}}
int add(int a[5])
{
int i,num;
cout<<"enter index on which the number is to be add:";
cin>>i;
cout<<"enter value to add: ";
cin>>num;
a[i]=a[i]+num;

return a[5];
}

int update(int a[5])
{

int i;
cout<<"enter index number which you want to update:";
cin>>i;
cout<<endl<<"enter updated value: ";
cin>>a[i];

return a[5];
}

int delet(int a[5])
{

int i;
cout<<"enter index number which you want to delet:";
cin>>i;
cout<<endl<<"enter 0 to delet value: ";
cin>>a[i];

return a[5];
}














































Monday 18 December 2017

how to sort integer array numbers/elements in Ascending Order in C++

- No comments
#include <iostream>
using namespace std;

#define MAX 100

int main()
{
 //array declaration
 int arr[MAX];
 int n,i,j;
 int temp;
 
 //read total number of elements to read
 cout<<"Enter total number of elements to read: ";
 cin>>n;
 
 //check bound
 if(n<0 || n>MAX)
 {
  cout<<"Input valid range!!!"<<endl;
  return -1;
 }
 
 //read n elements
 for(i=0;i<n;i++)
 {
  cout<<"Enter element ["<<i+1<<"] ";
  cin>>arr[i];
 }
 
 //print input elements
 cout<<"Unsorted Array elements:"<<endl;
 for(i=0;i<n;i++)
  cout<<arr[i]<<"\t";
 cout<<endl;
 
 //sorting - ASCENDING ORDER
 for(i=0;i<n;i++)
 {  
  for(j=i+1;j<n;j++)
  {
   if(arr[i]>arr[j])
   {
    temp  =arr[i];
    arr[i]=arr[j];
    arr[j]=temp;
   }
  }
 }
 
 //print sorted array elements
 cout<<"Sorted (Ascending Order) Array elements:"<<endl;
 for(i=0;i<n;i++)
  cout<<arr[i]<<"\t";
 cout<<endl; 
 
 
 return 0;
 
}

Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix.

Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix. ...

propeller ads

PropellerAds