EECE 231 Lab 1 Solution, Fall 2014

American University of Beirut · Introduction to Programming Using C++ and MATLAB · 3 pages · Prof. Fadi Zaraket · with solution

All EECE 231 files
EECE 231 Lab 1 Solution, Fall 2014, page 1

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

EECE 231 Lab 1 Solution, Fall 2014, page 2 EECE 231 Lab 1 Solution, Fall 2014, page 3

More EECE 231 files

Show the text of this lab
//============================================================================ // Name : pa1_p1.cpp // Author : HusseinSibai // Description : Solution of problem 1 of the pa1 in EECE231 \ Fall 2014 //============================================================================ #include <iostream> using namespace std; int main() { cout << "************************************************************" << endl; cout << "*" <<endl; cout << "*\tWelcome to c++ programming" <<endl; cout << "*" <<endl; cout << "************************************************************" << endl; return 0; } //Problem Assignment 1, Fall 14/15 //Problem 2 //Author: Maya Safieddine #include <iostream> using namespace std; int main() { //declare four variables of type integer (int): int i1, i2, i3, i4; cout<<"Please enter four integer number"<<endl; //Prompts the user to input the four integers i1, i2, i3, and i4. cin>>i1; cin>>i2; cin>>i3; cin>>i4; //print out the variables cout<<"\nThe input values are:"<<endl; cout<<i1<<endl; cout<<i2<<endl; cout<<i3<<endl; cout<<i4<<endl; //compute the sum of the vairables, and store the result in variable sum int sum = i1 + i2+i3+i4; //print the sum variable value cout<<"\nSum :"<<sum<<endl; //\n: new line //compute the average of the variables and save them in variable average of type double double average= sum/4.0; //we reuse the variable sum since it already has the addition value of the integers //we use 4.0 to imply a denominator of type double, so that the result of the arithmetic devision is in decimal (not truncated) cout<<"Average :"<<average<<endl; return 0; } /* * course: EECE 231 * Lab: 1 * Problem: 3 * author: Ameen Jaber */ #include <iostream> using namespace std; int main() { // declare variables int totalSeconds, seconds, minutes, hours; // Read the elapsed time from the user cout << "Please enter elapsed time: "; cin >> totalSeconds; // Calculate the hours, minutes, and seconds hours = totalSeconds / 3600; int remainder = totalSeconds % 3600; minutes = remainder / 60; seconds = remainder % 60; // Print the converted time cout << "Converted time: " << hours << ':' << minutes << ':' << seconds << endl; return 0; }