EECE 230 Homework 1, Spring 2012
American University of Beirut · Introduction to Programming · 3 pages · Dr. Ali Hajj
More EECE 230 files
Show the text of this homework
//NAME:Ahmad Husseini
//ID NUMBER:201105045
//Problem 1:
//Part a:
//#include<iostream>
//using namespace std;
//void main ()
//{
//
system("cls");
//
int grade1, grade2, grade3, grade4, grade5;
//
int averageGradeInteger;
//
double averageGradeDouble;
//
cout<<"Please enter the grades of the five courses seperated by
whitespaces :"<<endl;
//
cin>>grade1>>grade2>>grade3>>grade4>>grade5;
//
averageGradeInteger= (grade1+grade2+grade3+grade4+grade5)/5;
//
averageGradeDouble= (grade1+grade2+grade3+grade4+grade5)/5.0;
//
cout<<"the average grade of the five courses
is :"<<averageGradeInteger<<endl;
//
cout<<"the average grade of the five courses
is :"<<averageGradeDouble<<endl;
//
//}
//Part b:
//#include<iostream>
//using namespace std;
//void main ()
//{
//
system("cls");
//
int grade1, grade2, grade3, grade4, grade5;
//
int averageGrade;
//
char comma;
//
cout<<"Please enter the grades of the five courses seperated by
commas :"<<endl;
//
cin>>grade1>>comma>>grade2>>comma>>grade3>>comma>>grade4>>comma>>grade5;
//
averageGrade= (grade1+grade2+grade3+grade4+grade5)/5;
//
cout<<"the average grade of the five courses is :"<<averageGrade<<endl;
//
//}
//Problem 2:
//#include<iostream>
//#include<cmath>
//using namespace std;
//void main ()
//{
//
system("cls");
//
double a, b, c, d;
//
cout<<"Please enter the coefficients of a second order equation :"<<endl;
//
cin>>a>>b>>c;
//
d=b*b-4*a*c;
//
double x1, x2;
//
x1=(-b-sqrt(d))/(2*a);
//
x2=(-b+sqrt(d))/(2*a);
//
cout<<"we have two solutions for the pervious equation : "<<x1<<" and
"<<x2<<endl;
//
//
//}
//Problem 3:
//#include<iostream>
//#include<cmath>
//using namespace std;
//void main ()
//{
//
int number;
//
cout<<"please enter a number of three digits :"<<endl;
//
cin>>number;
//
int digit1, digit2, digit3;
//
digit1=number/100;
//
digit2=(number/10)%10;
//
digit3=number%10;
//
cout<<"the three digits are :\t"<<digit1<<"\t"<<digit2<<"\t
"<<digit3<<endl;
//
//
//}
Assignment 1
1- write a complete program that asks a student to enter integer grades in 5 courses, calculates and displays
the grade average. Write two versions of your program:
a- The grades are entered separated by whitespaces
b- The grades are entered separated by commas.
Use meaningful names for your variables
2- Write a program that asks the user to enter the coefficients of a second order equation, calculates and
displays the roots. ( Solution of ax2+bx+c=0)
Assume there is solution. Use sqrt function of cmath library
3- Write a program that asks the user to enter an integer on 3 digits, extract and display each digit.