Professional Documents
Culture Documents
#include <iostream>
using namespace std;
int main()
{
char input, alphabet = 'A';
cout << "Enter the uppercase character you want to print in the last row: ";
cin >> input;
___________________________________________________________________________________
_
/*C++ program for Calculation of the surface and the volume of a cone
Write a program that calculates the volume of a solid cone. The formula is:
volume=(PI x radius² x height)/3 Read in the values for the parameters
height and radius(as floating point numbers). Then the program should
calculate the volume considering the following restriction :radius and height
must be greater than0 If the user types in a correct value for one of the
variables ,the program should print out an error message and quit .
Otherwise ,it displays the result.*/
#include<iostream>
using namespace std;
float pi = 3.14159;
// Function to calculate
// Volume of cone
float volume(float r, float h)
{
return (float(1) / float(3)) * pi * r * r * h;
}
// Function to calculate
// Surface area of cone
float surface_area(float r, float s)
{
return pi * r * s + pi * r * r;
}
// Driver Code
int main()
{
float radius ;
float slant_height ;
float height ;
float vol, sur_area;
return 0;
}
___________________________________________________________________________________
________
int main()
{
int i, j, n, sum = 0, tsum;
cout << "\n\n Find the sum of the series (1) + (1+2) + (1+2+3) + (1+2+3+4)
+ ... + (1+2+3+4+...+n):\n";
cout <<
"----------------------------------------------------------------------------------
--------\n";
cout << " Input the value for nth term: ";
cin >> n;
for (i = 1; i <= n; i++)
{
tsum = 0;
for (j = 1; j <= i; j++)
{
sum += j;
tsum += j;
cout << j;
if (j < i)
{
cout << "+";
}
}
cout << " = " << tsum << endl;
}
cout << " The sum of the above series is: " << sum << endl;
}
___________________________________________________________________________________
___________________________________________________________________________________
______________
______________________________________________________LabActivy
2__________________________________________________________________________________
_______________________
//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)
{
// Update array
for (int i = 0; i <= y - 2; i++)
arr[i] = arr[i + 1];
___________________________________________________________________________________
__________________________
/*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()
{
f:
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;
}
goto f;
___________________________________________________________________________________
__________________________
// C++ Program to Delete an Element from an Array
#include<iostream>
using namespace std;
int main()
{
int arr[5], 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[5], arrTwo[8], arrMerge[20];
int sizeOne, sizeTwo, a, y;
cout<<"Enter the Size for First Array: ";
cin>>sizeOne;
cout<<"Enter "<<sizeOne<<" Elements for First Array: ";
for(a=0; a<sizeOne; a++)
{
cin>>arrOne[a];
arrMerge[a] = arrOne[a];
}
y = a;
cout<<"\nEnter the Size for Second Array: ";
cin>>sizeTwo;
cout<<"Enter "<<sizeTwo<<" Elements for Second Array: ";
for(a=0; a<sizeTwo; a++)
{
cin>>arrTwo[a];
arrMerge[y] = arrTwo[a];
y++;
}
cout<<"\nThe New Array (Merged Array):\n";
for(a=0; a<y; a++)
cout<<arrMerge[a]<<" ";
cout<<endl;
return 0;
}
___________________________________________________________________________________
____
___________________________________________________________________________________
__________________________________