EECE 230 Lab Report, Spring 2008

American University of Beirut · Introduction to Programming · 3 pages

All EECE 230 files
EECE 230 Lab Report, Spring 2008, page 1

Stuck on a question? A tutor can walk you through it.

EECE 230 Lab Report, Spring 2008, page 2 EECE 230 Lab Report, Spring 2008, page 3

More EECE 230 files

Show the text of this lab
#include <iostream> using namespace std; float main(){ cout<<"Ex 2-7:\n\n"; cout << "======================================================\ n******************************************************\n Welcome to C++ \n"; cout<<"******************************************************\ n======================================================\n\n\n"; cout<<"Ex 2-9:\n\n"; float c1,c2,c3,c4,c5; cout<<"Enter 1st number: "; cin>>c1; cout<<"Enter 2nd number: "; cin>>c2; cout<<"Enter 3rd number: "; cin>>c3; cout<<"Enter 4th number: "; cin>>c4; cout<<"Enter 5th number: "; cin>>c5; cout<<"The five numbers are: "<<c1<<", "<<c2<<", "<<c3<<", "<<c4<<", and "<<c5; int i1=static_cast<int>(c1+0.5); int i2=static_cast<int>(c2+0.5); int i3=static_cast<int>(c3+0.5); int i4=static_cast<int>(c4+0.5); int i5=static_cast<int>(c5+0.5); cout<<"\n\nThe nearest integer of the 1st number is "<<i1; cout<<"\nThe nearest integer of the 2nd number is "<<i2; cout<<"\nThe nearest integer of the 3rd number is "<<i3; cout<<"\nThe nearest integer of the 4th number is "<<i4; cout<<"\nThe nearest integer of the 5th number is "<<i5; int sum=i1+i2+i3+i4+i5; cout<<"\n\nTheir sum is "<<sum; float average=sum/5.0; cout<<"\nAnd their average is "<<average<<"\n\nEx 2-12:\n"; int hour; int min; int sec; cout<<"Enter the number of hours: "; cin>>hour; cout<<"Enter the number of minutes: "; cin>>min; cout<<"Enter the number of seconds: "; cin>>sec; int time=(hour*3600)+(min*60)+(sec); cout<<"\nThe time in seconds is "<<time<<"\n\n"; return 0; } #include <iostream> using namespace std; void main() { int array[100], i, j, targetSum, integer; cout<<"Enter the target sum: "; cin>>targetSum; for (i=0; i < 100 && integer != 999;i++) { cout<<"Enter integer: "; cin>>integer; array[i] = integer; } i=0; j = i + 1; while (i<100) { j=i; while (j < 100) { if (array[j] + array[i] == targetSum) { cout<<"("<<array[i]<<","<<array[j]<<")\n"; } j++; } i++; } }