Anda di halaman 1dari 6

Subject: Programming application Lab 8

Date: 1/4/2013
Instructor: Abdulaziz(network security PhD candidate)
Time: two hours
Lab teaching method: writing all lab programs correctly
in your group with cooperation with subject Instructor.
Important note:
1.
2.
3.

writing the lab programs in group (three students each).


Practical exam has 40% from the subject marks, 20% for
Programming in the lab.
each group required to show their programs.

////////////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std;
int main()
{
// Declare the members of the array
int numbers[] = {8, 25, 36, 44, 52, 60, 75, 89};
int find,t;
int i, m = 8;
cout << "Enter a number to search: ";
cin >> find;
for (i = 0; (i < m) && (numbers[i] != find); ++i)
continue;
//Find whether the number typed is a member of the
array
if (i == m)
cout << find << " is not in the list" << endl;
else
cout << find << " is the " << i + 1
<< "th element in the list" << endl;
cin>>t;
return 0;
}
//////////////////////////////////////

Example of finding the minimum member of an array


#include <iostream>
using namespace std;
int main()
{
// The members of the array
int numbers[] = {8, 25, 36, 44, 52, 60, 75, 89};
int minimum = numbers[0];
int a = 8;
int t;
// Compare the members
for (int i = 1; i < a; ++i) {
if (numbers[i] < minimum)
minimum = numbers[i];
}
// Announce the result
cout << "The lowest member value of the array is "
<< minimum << "." << endl;
cin>>t;
return 0;
}
///////////////////////////////////////////////////////
/////////////////////////////////////////////
#include <iostream>
using namespace std;
int main()
{
// The members of the array
int numbers[] = {8, 25, 36, 44, 52, 60, 75, 89};
int maximum = numbers[0];
int a = 8;
int t;
// Compare the members
for (int i = 1; i < a; ++i) {

if (numbers[i] > maximum)


maximum = numbers[i];
}
// Announce the result
cout << "The highest member value of the array is
"
<< maximum << "." << endl;
cin>>t;
return 0;
}
///////////////////////////////////////////////////////
//////////////////////////////////////////
#include <iostream>
using namespace std;
void DisplayTheArray(double member[])
{ int t;
for(int i = 0; i < 5; ++i)
cout << "\nDistance " << i + 1 << ": " <<
member[i];
cout << endl;
cin>>t;
}
int main()
{
const int numberOfItems = 5;
double distance[numberOfItems] = {44.14, 720.52,
96.08, 468.78, 6.28};
cout << "Members of the array";
DisplayTheArray(distance);
return 0;
}
///////////////////////////////////////////////////////
//////////////////////////////////////

#include <iostream>
using namespace std;
#include <iomanip>
using std::setw;
int main ()
{
int n[ 10 ]; // n is an array of 10 integers
int t;
// initialize elements of array n to 0
for ( int i = 0; i < 10; i++ )
{
n[ i ] = i + 100; // set element at location i to
i + 100
}
cout << "Element" << setw( 13 ) << "Value" << endl;
// output each array element's value
for ( int j = 0; j < 10; j++ )
{
cout << setw( 7 )<< j << setw( 13 ) << n[ j ] <<
endl;
}
cin>>t;
return 0;
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////
#include <iostream>
using namespace std;
int main ()
{
int var1,t;
char var2[10];
cout << "Address of var1 variable: ";
cout << &var1 << endl;

cout << "Address of var2 variable: ";


cout << &var2 << endl;
cin>>t;
return 0;
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
#include <iostream>
using namespace std;
// function declaration
int max(int num1, int num2);
int main ()
{
// local variable declaration:
int a = 100;
int b = 200;
int ret;
int t;
// calling a function to get max value.
ret = max(a, b);
cout << "Max value is : " << ret << endl;
cin>>t;
return 0;
}
// function returning the max between two numbers
int max(int num1, int num2)
{
// local variable declaration
int result;
if (num1 > num2)
result = num1;
else
result = num2;

return result;
}
Exercise1:
1. Write a program which send array on five numbers,
than return the biggest one.

Anda mungkin juga menyukai