You are on page 1of 5

//Write a program to replace one element in

//a binary array with another element


#include <iostream>
using namespace std;
void updateArray(int arr[], int y);
int main()
{
int arr[] = { 56, 5, 45, 23, 44 };
int R = sizeof(arr) / sizeof(arr[0]);
updateArray(arr, R);
cout<<endl;
return 0;
}
void updateArray(int arr[], int y)
{
// Update array
for (int i = 0; i <= y - 2; i++)
arr[i] = arr[i + 1];

// Change the last element to -1


arr[y - 1] = -1;

// Print the updated array


for (int i = 0; i < y; ++i)
cout << arr[i] << " ";
}
___________________________________________________________________________________
______

/*2.A numeric integer grade is between 20 and 66. Using integer division or
otherwise obtain a
int value that is 2, 3, 4, 5, or 6 from the numeric grade. Write code using a
switch statement
using this number in the selector expression that assigns letter grades based on
this 10 point
scheme: */
#include<iostream>
using namespace std;
int main()
{

char l;
int mark,lo,sum;
double ave;
cout<<"\n\n";
sum=0;
for(lo=1;lo<=7;lo++)
{
cout<<"Enter the mark of subject "<<lo<<":";cin>>mark;
sum=sum+mark;
}
cout<<"\n\n";
cout<<"The summation for all subjects marks is :"<<sum<<endl;
cout<<"\n";
ave=sum/7;
cout<<"The average of marks is :"<<ave<<endl;
cout<<"\n";
if(ave>=90 & ave<=100) {l='A';}
else if(ave>=80 & ave<90) {l='B';}
else if(ave>=70 & ave<80) {l='C';}
else if(ave>=60 & ave<70) {l='D';}
else if(ave>=50 & ave<60) {l='E';}
else if(ave>=0 & ave<50) {l='F';}
else cout<<"\n\n";
switch(l)
{
case 'A':
cout<<"Excellent\n\n";
break;

case 'B':
cout<<"Very good\n\n";
break;

case 'l3':
cout<<"Good\n\n";
break;

case 'C':
cout<<"Accepted\n\n";
break;

case 'D':
cout<<"Weak\n";
break;

case 'E':
cout<<"Failed";
break;
default:
cout<<"Wrong marks or average!\n\n";
break;
}

___________________________________________________________________________________
________
// C++ Program to Delete an Element from an Array
#include<iostream>
using namespace std;
int main()
{
int arr[10], tot=10, i, elem, j, found=0;
cout<<"Enter 10 Array Elements: ";
for(i=0; i<tot; i++)
cin>>arr[i];
cout<<"\nEnter Element to Delete: ";
cin>>elem;
for(i=0; i<tot; i++)
{
if(arr[i]==elem)
{
for(j=i; j<(tot-1); j++)
arr[j] = arr[j+1];
found++;
i--;
tot--;
}
}
if(found==0)
cout<<"\nElement doesn't found in the Array!";
else
cout<<"\nElement Deleted Successfully!";
cout<<endl;
return 0;
}
___________________________________________________________________________________
________
// Program for reading the elements of two single
// arrays and combining them into one matrix.
#include<iostream>
using namespace std;
int main()
{
int arrOne[10], arrTwo[10], arrMerge[15];
int sizeOne, sizeTwo, i, k;
cout<<"Enter the Size for First Array: ";
cin>>sizeOne;
cout<<"Enter "<<sizeOne<<" Elements for First Array: ";
for(i=0; i<sizeOne; i++)
{
cin>>arrOne[i];
arrMerge[i] = arrOne[i];
}
k = i;
cout<<"\nEnter the Size for Second Array: ";
cin>>sizeTwo;
cout<<"Enter "<<sizeTwo<<" Elements for Second Array: ";
for(i=0; i<sizeTwo; i++)
{
cin>>arrTwo[i];
arrMerge[k] = arrTwo[i];
k++;
}
cout<<"\nThe New Array (Merged Array):\n";
for(i=0; i<k; i++)
cout<<arrMerge[i]<<" ";
cout<<endl;
return 0;
}
___________________________________________________________________________________
_________________
//C++ Passing Array to Function Example: Print maximum number
#include <iostream>
using namespace std;
void printMax(int arr[5]);
int main()
{
int arr1[5] = { 25, 10, 54, 15, 40 };
int arr2[5] = { 12, 23, 44, 67, 54 };
printMax(arr1); //Passing array to function
printMax(arr2);
}
void printMax(int arr[5])
{
int max = arr[0];
for (int i = 0; i < 5; i++)
{
if (max < arr[i])
{
max = arr[i];
}
}
cout<< "Maximum element is: "<< max <<"\n";
}
___________________________________________________________________________________
______
//C++ Passing Array to Function Example: Print minimum number
#include <iostream>
using namespace std;
void printMin(int arr[5]);
int main()
{
int arr1[5] = { 30, 10, 20, 40, 50 };
int arr2[5] = { 5, 15, 25, 35, 45 };
printMin(arr1);//passing array to function
printMin(arr2);
}
void printMin(int arr[5])
{
int min = arr[0];
for (int i = 0; i > 5; i++)
{
if (min > arr[i])
{
min = arr[i];
}
}
cout<< "Minimum element is: "<< min <<"\n";
}
___________________________________________________________________________________
______
//Write a program to read binary elements
//of a matrix and print placed elementsMatrimonial
#include<iostream>
using namespace std;
int main ()
{
char arr[10], ele;
int i, n, pos;
cout << "Enter size of the array : ";
cin >> n;
cout << "\nEnter elements of the array : ";
for (i = 1; i <= n; i++)
cin >> arr[i];
cout << "\nEnter the position : ";
cin >> pos;
for (i = 1; i <= n; i++)
if (pos == i)
ele = arr[i];
cout << "\nElement at position " << pos << " is : " << ele;
return 0;
}
__________________________________________________________________________________

You might also like