0% found this document useful (0 votes)
62 views19 pages

Ajman University College of Engineering and IT Biomedical Engineering Department BME103 / Computer Programming Spring 19-20

This document contains the final assignment for a student named Sahar Khalid Mattar with student ID 201910159 for the Computer Programming course at Ajman University College of Engineering and IT in the Biomedical Engineering Department. The assignment contains multiple questions involving C++ programming of matrices, arrays, and finding maximum/minimum values. The student provides code and output for the questions.

Uploaded by

Sahar Mattar
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)
62 views19 pages

Ajman University College of Engineering and IT Biomedical Engineering Department BME103 / Computer Programming Spring 19-20

This document contains the final assignment for a student named Sahar Khalid Mattar with student ID 201910159 for the Computer Programming course at Ajman University College of Engineering and IT in the Biomedical Engineering Department. The assignment contains multiple questions involving C++ programming of matrices, arrays, and finding maximum/minimum values. The student provides code and output for the questions.

Uploaded by

Sahar Mattar
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/ 19

Ajman University

College of Engineering and IT


Biomedical Engineering Department
BME103 / Computer programming
Spring 19-20

Final Assignment

Student name : sahar khalid mattar


Student ID: 201910159

Instructor: Kanhira k.Mujeeb Rahman


Follow q5:
Follow q6:
1. Write a C++ program that is used to do the following matrix operation 2A + 4 B,
where A and B should be 3X4 matrices asking the user to enter random
numbers. Write the code and show the output.

#include <iostream> ////sahar khalid mattar 201910159


#include<cstdlib>
using namespace std;
void main()
{
int a[3][4], b[3][4], c[3][4];

//////matrix a
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout << "Enter a[" << i << "]"<<"["<<j<<"]"<< endl;
cin >> a[i][j];
}
}

///////matrix b
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout << "Enter b[" << i << "]" << "[" << j << "]" << endl;
cin >> b[i][j];
}
}

/////using the operation 2A+4B to calculate and find the output matrix
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
c[3][4] = 2*a[i][j] + 4*b[i][j];
}
}

////output matrix
cout << "************output matrix*************" << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout<<c[3][4]<<'\t' ;
}
cout << endl;
}

system("pause");
}
#include <iostream> ////sahar khalid mattar 201910159
using namespace std;
void main()
{
int marks[50];
//////singel dimention array that have the marks of 50 student//////
for (int i = 0; i < 50; i++)
{
cout << "Enter the student mark [" << i + 1 << "]" << endl;
cin >> marks[i];
}

//////finding the maximum and the minimum marks


int max=0, min=50;
for (int i = 0; i < 50; i++)
{
if (marks[i] < min) ////min marks
min = marks[i];
if (marks[i] > max) ////max marks
max = marks[i];
}
cout << "****************************" << endl;
cout << "min marks= " << min << endl;
cout << "****************************" << endl;
cout << "max marks= " << max << endl;

system("pause");
}
1. Define a single dimension array for storing marks scored by 100 students and
write a C++ code to display the average marks and SD (Standard Deviation).

#include <iostream> ////sahar khalid mattar 201910159


using namespace std;
void main()
{
int marks[100];
//////singel dimention array that have the marks of 10 student//////
for (int i = 0; i < 10; i++)
{
cout << "Enter the student mark [" << i + 1 << "]" << endl;
cin >> marks[i];
}

//////finding the sum value and the sd ////intilizing sum , variance ,


avrg

float sum=0.0 , mean , variance=0.0, sd , avrg=0.0;


for (int i = 0; i < 10; i++)
{
sum = sum + marks[i]; /////the equation to
calculate the sd
mean = (sum / 10);
variance = variance + pow((marks[i] - mean), 2);
variance = variance / 10;
sd = sqrt(variance); ////we find the square root
of the variance
avrg = avrg + marks[i]; ////we find the sum/10 so
we can find the average
}
cout << "****************************" << endl;
cout << "average= " << mean << endl;
cout << "****************************" << endl;
cout << "SD= " << sd << endl;

system("pause");
}
‫اساله من الكالس‬
No argument no return ---root
#include <iostream>
void output();
void roots();
using namespace std;
int a, b, c;
void main()
{
output();
roots();
system("pause");
}

void output()
{
start: cout << "enter a , b ,c " << endl;
cin >> a >> b >> c;
if (a == 0)
{
cout << "*************a is zero !!! error try again!!!****************"
<< endl;
goto start;
}
}

void roots()
{
float d, root1, root2;
d = b * b - 4 * a * c;
root1 = (-b + sqrt(d)) / 2 * a;
root2 = (-b - sqrt(d)) / 2 * a;
if (d >= 0)
{
cout << "root1= " << root1 << " root2=" << root2 << endl;
}
else
cout << "roots are imagenary" << endl;
}
Argument and no return

/////argument=the basket is full "carry", and no return=void/////


#include <iostream>
void roots(float,float,float);
using namespace std;
void main()
{
int a, b, c; //////local bc of argument ‫هم و غم‬

start: cout << "enter a , b ,c " << endl;


cin >> a >> b >> c;
if (a == 0)
{
cout << "*************a is zero !!! error try again!!!****************"
<< endl;
goto start;
}
roots(a,b,c);
system("pause");
}

void roots(float a , float b , float c)


{
float d, root1, root2;
d = b * b - 4 * a * c;
root1 = (-b + sqrt(d)) / 2 * a;
root2 = (-b - sqrt(d)) / 2 * a;
if (d >= 0)
{
cout << "root1= " << root1 << "root2=" << root2 << endl;
}
else
cout << "roots are imagenary" << endl;
}
Argument with return

/////argument=the basket is full "carry", and return=void/////


#include <iostream>
float root1(float,float,float);
float root2(float, float, float);
using namespace std;
void main()
{
int a, b, c; //////local bc of argument

start: cout << "enter a , b ,c " << endl;


cin >> a >> b >> c;
if (a == 0)
{
cout << "*************a is zero !!! error try again!!!****************"
<< endl;
goto start;
}
cout << "root1=" << root1(a, b, c) << "root2" << root2(a, b, c) << endl;
system("pause");
}

float root1(float a , float b , float c)


{
float d, root1;
d = b * b - 4 * a * c;
root1 = (-b + sqrt(d)) / 2 * a;
if (d >= 0)
{
root1 = (-b + sqrt(d)) / 2 * a;
return root1;
}
else
cout << "roots are imagenary" << endl;
}

float root2(float a, float b, float c)


{
float d, root2;
d = b * b - 4 * a * c;
if (d >= 0)
{
root2 = (-b - sqrt(d)) / 2 * a;
return root2;
}
else
cout << "roots are imagenary" << endl;
}
1111

1111

2222

2222

#include <iostream>
using namespace std;
void main()
{
int a[8][8];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (i < 4)
{
a[i][j] = 1;
}
else
a[i][j] = 2;
}
}
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
cout << a[i][j];
}
cout << endl;
}

system("pause");
}
The last one

#include <iostream>
using namespace std;
void main()
{
int a[4][4];
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (i <= 2 , j> 2)
{
a[i][j] = 2;
}
else if (i <= 2, j < 2)
{
a[i][j] = 1;
}
else if (i > 2, j > 2)
{
a[i][j] = 1;
}
else if (i > 2, j <= 2)
{
a[i][j] = 2;
}
}
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << a[i][j];
}
cout << endl;
}

system("pause");
}

You might also like