Dsa - Assignment 1
Dsa - Assignment 1
1)Q
#include<iostream>
#include<iomanip>
#include <string>
using namespace std;
int main()
{
string item[5]={"brinjal","bitter guard","bottle guard","onion","tomato"};
int quantity[5]={};
int price[5]={11,22,69,88,25};
double bill[5]={};
double totalprice=0.0;
for(int i=0;i<5;i++)
{
cout<<"please enter the qunatity of each vegetables "<<item[i]<<"s needed"<<endl;
cin>>quantity[i];
bill[i]=quantity[i]*price[i];
totalprice=bill[i]+totalprice;
}
cout<<setw(15)<<"vegetables"<<setw(20)<<"price/kg"<<setw(7)<<"quantity"<<setw(7)<<"cost"<<endl;
for(int j=0;j<5;j++)
{
cout<<setw(15)<<item[j]<<setw(20)<<price[j]<<setw(7)<<quantity[j]<<setw(7)<<bill[j]<<endl;
}
cout<<setw(15)<<"Total price"<<setw(20)<<setprecision(2)<<totalprice<<endl;
return 0;
}
OUTPUT :
2)Q
#include<iostream>
using namespace std;
int main()
{
int marks;
cout<<"ENTER THE MARKS OBTAINED OUT OF 100"<<endl;
cin>>marks;
switch(marks/10)
{
case (10):
case(9): cout<<"Grade='S'"<<endl;
break;
case(8): cout<<"Grade='A'"<<endl;
break;
case(7): cout<<"Grade='B'"<<endl;
break;
case(6): cout<<"Grade='C'"<<endl;
break;
case(5): cout<<"Grade='D'"<<endl;
break;
case(4): cout<<"Grade='E'"<<endl;
break;
case(3): cout<<"Grade='F'"<<endl;
break;
case(2):cout<<"Grade='F'"<<endl;
break;
case(1):cout<<"Grade='F'"<<endl;
break;
default:cout<<"Invalid marks entered";
break;
}
return 0;
}
OUTPUT
3Q)
#include <iostream>
using namespace std;
int main()
{
char opp;
double n1, n2, sum , subtraction , multiplication , result ;
cout << "please Enter the mathematical operation you want to perform (+, -, *, /): ";
cin >> opp;
cout << "please Enter the first number: ";
cin >> n1;
cout << "please Enter the second number: ";
cin >> n2;
switch (opp)
{
case '+':
sum = n1 + n2;
cout << "The result calaculated is: " << sum << endl;
break;
case '-':
subtraction = n1 - n2;
cout << "The result calaculated is: " << subtraction << endl;
break;
case '*':
multiplication = n1 * n2;
cout << "The result calaculated is: " << multiplication << endl;
break;
case '/':
if (n2 != 0)
{
result = n1 / n2;
cout << "The result calaculated is: " << result << endl;
} else
cout << "Division not possible as denominator is 0" << endl;
break;
default:
cout << "Invalid input" << endl;
}
return 0;
}
OUTPUT
4Q)
#include <iostream>
using namespace std;
int main()
{
int matrix1[3][3];
return 0;
}
OUTPUT :
5Q)
#include <iostream>
using namespace std;
int main()
{
int rows = 5;
OUTPUT:
5Q)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Calendar for month of August 2014\n\n";
cout << "Sun Mon Tue Wed Thu Fri Sat\n";
int startingDay = 5;
int daysInaMonth = 31;
return 0;
}
OUTPUT:
6Q)
#include <iostream>
using namespace std;
int main()
{
int n, rev = 0, sum= 0;
cout << "Enter a 6-digit number: ";
cin >> n;
if (n < 100000 || n > 999999)
{
cout << "Enter a valid 6 digit number" << endl;
return 1;
}
int temp = n;
while (temp > 0)
{
int digit = temp % 10;
rev = rev * 10 + digit;
sum=sum+digit;
temp /= 10;
}
cout << "The Reversed Number= " << rev << endl;
cout << "Sum of Digits of given number= " << sum << endl;
return 0;
}
OUTPUT :
Set 2
#include <iostream>
using namespace std;
long long factorial(int num)
{
long long facto = 1;
for (int i = 1; i <= num; i++)
{
facto=facto*i;
}
return facto;
}
int pow(int m1,int m2)
{
int powertothe =1;
for(int i=1;i<=m2;i++)
{
powertothe=powertothe*m1;
}
return powertothe;
}
int main()
{
int n;
double x, sum = 0.0;
cout << "Enter the value of x ";
cin >> x;
cout << "Enter the number of terms ";
cin >> n;
for (int i = 1; i <= n; i++)
{
sum=sum+(pow(x,i)/factorial(i));
}
cout << "The sum of the series is= " << sum << endl;
return 0;
}
OUTPUT
2)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int x;
cout << "Enter the valid value of x ";
cin >> x;
for (int i = 1; i <= 5; i++)
{
for (int gap = 5; gap > i; gap--)
{
cout << " ";
}
for (int j = 1; j <= i; j++)
{
cout << "x^" << i << "+" << j << " ";
}
cout << endl;
}
return 0;
}
Output
3)Q
#include <iostream>
using namespace std;
int main()
{
int rows = 6;
return 0;
}
OUTPUT :