Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views7 pages

Prog Assignment

Uploaded by

iirwed79
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)
52 views7 pages

Prog Assignment

Uploaded by

iirwed79
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/ 7

//Prog 1

#include <iostream>
#include <string>
using namespace std;
string DeciToBi(int x);

int main() {
for(int x=1;x<=100;x++)
{
cout << x << "= " << DeciToBi(x) <<"\n";
}
}

string DeciToBi(int x)
{
string r;
while (x > 0) {
if (x % 2 == 0) {
r = "0" + r;
} else {
r = "1" + r;
}
x /= 2;
}
return r;
}

//Prog 2

#include <iostream>
using namespace std;
void MatMul(int a[3][3], int b[3][3], int c[3][3]);
int main()
{
int a[3][3], b[3][3], c[3][3];
cout << "Enter elements of matrix number 1 : \n";
for (int x = 0; x < 3; ++x)
for (int y = 0; y < 3; ++y)
{
cout << "Enter element M(1)" << x + 1 << y + 1 << " : ";
cin >> a[x][y];
}

cout<< "\nEnter elements of matrix number 2 : \n";


for (int x = 0; x < 3; ++x)
for (int y = 0; y < 3; ++y)
{
cout << "Enter element M(2)" << x + 1 << y + 1 << " : ";
cin >> b[x][y];
}

for (int x = 0; x < 3; ++x)


for (int y = 0; y < 3; ++y)
{
c[x][y] = 0;
}

MatMul(a, b, c);

}
void MatMul(int a[3][3], int b[3][3], int c[3][3])
{

for (int x = 0; x < 3; ++x)


for (int y = 0; y < 3; ++y)
for (int z = 0; z < 3; ++z)
{
c[x][y] += a[x][z] * b[z][y];
}
cout << endl << "Output Matrix: \n";
for (int x = 0; x < 3; ++x)
{
for (int y = 0; y < 3; ++y)
{
cout << " " << c[x][y];

}
cout<<"\n";
}

//Prog 3

#include <iostream>
#include <iomanip>
using namespace std;
double CalCharges( double H );

int main()
{
double F, S, T;

cout << "Enter hours for three customers to calculate their charges : \n";
cin >> F >> S >> T;
cout << "Car\tHours\tCharge\n";
cout << "1\t" << F<< "\t" << CalCharges( F )<<" SAR\n";
cout << "2\t" << S<< "\t" << CalCharges( S ) <<" SAR\n";
cout << "3\t" << T << "\t" << CalCharges( T ) <<" SAR\n";
cout << "TOTAL\t" << F + S + T << "\t"
<< CalCharges( F ) + CalCharges( S ) + CalCharges( T )<<" SAR\n";

return 0;
}

double CalCharges( double H )


{
if( H < 3 )
return 5;
else
{
if ( H < 24 )
return 5 + ( H - 2 ) * 1;
else
return 25;
}
}

//Prog 4

#include<iostream>
using namespace std;
int main()
{
int co;
float charges=0,total=0;
cout<<"Enter the Electricity consumed KWh: \n";
cin>>co;
if(co>3000)
{
charges=co*0.30;
}
else if(co>2000)
{
charges=co*0.20;

}
else if(co>1000)
{
charges=co*0.15;
}
else
{
charges=co*0.10;
}
total=charges;
cout<<"The Bill total is : "<<total<<" SR";
}

//Prog 5

#include <iostream>
using namespace std;

int main()
{
const int row = 5;
const int column = 3;
int marks[row][column];
int results[row];
int ranks[row];
int total;

for(int i=0; i<row; i++)


{
cout<<"Enter student"<<(i+1)<<" marks \n";
for(int j=0; j<column; j++)
{
cout<<"Enter marks[student"<<(i+1)<<"]"<<"[subject"<<(j+1)<<"] : ";
cin>>marks[i][j];
}
}
for(int i=0; i<row; i++)
{
total = 0;
for(int j=0; j<column; j++)
{
total+= marks[i][j];

results[i]=total;

}
}

for(int i=0; i<row; i++)


{
int count = 0;
for(int j=0; j<row; j++)
{
if (results[j] > results[i])
{
count++;
}
}
ranks[i] = count + 1;
}

for(int i=0; i<row; i++)


{

cout<<(i+1)<<"\t";
for(int j=0; j<column; j++)
{

cout<<marks[i][j]<<"\t";
}
cout<<results[i]<<" ";
cout<<ranks[i];
cout<<"\n";
}
return 0;
}

You might also like