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
More EECE 231 files
- Lab 1024 · Fall 2017LabView
- Lecture All C++ Slides · Fall 2015LabView
- Lecture All Matlab Slides · Fall 2015LabView
- Syllabus · Fall 2015LabView
- Lecture Second Textbook PDF · Fall 2015LabView
- Lecture All C++ Lectures · Fall 2015LabView
- Lecture All Matlab Lectures · Fall 2015LabView
- Lecture First Textbook PDF · Fall 2015LabView
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;
}