Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
IN THE NAME OF ALLAH, THE MOST BENEFICENT, THE MOST MERCIFUL
DEPARTMENT OF SCIENCES PROGRAMMES
CENTRE FOR FOUNDATION STUDIES, IIUM
SEMESTER II, SESSION 2009/2010
ESM1513/SEF1514 - COMPUTER II
QUIZ 2 (SET A)
Student Name: …………………………………………….…………. Matric No: ……….….………….
Group No: ……………..
Lecturer Name: ……………………………………………………………..
The owner of a strawberry farm has made the following arrangement with a group of students:
the may pick all the strawberries they want. When they are through picking, the strawberries will
be weighed. The farm will retain 50 percent of the strawberries and the students will divide the
remainder evenly among them. Assume that a strawberry weighs approximately 5g.
Write a complete program (12 marks) and draw the flowcharts (8 marks) for the above problem.
The requirements:
1) Use a function name GetStrawberry ( ) for the input (the weight of the strawberry in kg).
2) Use a function name GetStudent () for the input (the number of the students).
3) Use function name Calculate ( ) to calculate how many strawberries the farmer and each
students get.
4) Use function Display to display the answer.
(Hint: Function GetStrawberry(), GetStudent(), and Calculate() will be called from main while
function Display() will be called from Calculate()).
Sample output:
Enter the weight for the strawberry in (kg): 1
Enter number of students: 5
The farmer get 50 strawberries.
Each student get 10 strawberries.
Press any key to continue
#include <stdio.h>
float GetStrawberry();
int GetStudent();
void Calculate(float,int);
void Display(int, int);
int main()
{
float noStraw;
int noStudent;
noStraw = GetStrawberry();
noStudent = GetStudent();
Calculate(noStraw, noStudent);
return 0;
}
float GetStrawberry()
{
float weight;
printf("Enter the weight for the strawberry in (kg): ");
scanf("%f", &weight);
return weight;
}
int GetStudent()
{
int student;
printf("Enter number of students: ");
scanf("%d", &student);
return student;
}
void Calculate(float weight, int stud)
{
int straw,student,farmer;
straw = weight *1000/30;
student = straw/2/stud;
farmer = straw/2;
Display(student,farmer);
}
void Display(int student, int farmer)
{
printf("The farmer get %d strawberries.\n",farmer);
printf("Each student get %d strawberries.\n",student);
}
IN THE NAME OF ALLAH, THE MOST BENEFICENT, THE MOST MERCIFUL
DEPARTMENT OF SCIENCES PROGRAMMES
CENTRE FOR FOUNDATION STUDIES, IIUM
SEMESTER II, SESSION 2009/2010
ESM1513/SEF1514 - COMPUTER II
QUIZ 2 (SET B)
Student Name: …………………………………………….…………. Matric No: ……….….………….
Group No: ……………..
Lecturer Name: ……………………………………………………………..
A second-degree polynomial in x is given by the expression
known numbers and a is not equal to 0. The formula to find the roots:
, where a, b, and c are
Then, assume the result b2 – 4ac is always positive value.
Write a complete program (12 marks) and draw the flowcharts (8 marks) for the above problem.
The requirements:
1) Use 3 different functions for the input a, b and c such as GetA( ),GetB( ),GetC( ).
2) Use function name Calculate ( ) to solve the polynomial.
3) Use function Display ( ) to display the roots for the polynomial.
(Hint: Function GetA(), GetB(), GetC() and Calculate() will be called from main while function
Display() will be called from Calculate()).
Sample output:
Enter a: 1
Enter b: 6
Enter c: 2
The first root is -0.35
The second root is -5.65
Press any key to continue
#include <stdio.h>
#include <math.h>
int GetA();
int GetB();
int GetC();
void Calculate(int,int,int);
void Display(float,float);
int main()
{
int A,B,C;
A = GetA();
B = GetB();
C = GetC();
Calculate(A,B,C);
return 0;
}
int GetA()
{
int A;
printf("Enter a: ");
scanf("%d", &A);
return A;
}
int GetB()
{
int B;
printf("Enter b: ");
scanf("%d", &B);
return B;
}
int GetC()
{
int C;
printf("Enter c: ");
scanf("%d", &C);
return C;
}
void Calculate(int a, int b, int c)
{
float det,root1,root2;
det = sqrt((pow(b,2)) - 4*a*c);
root1 = (-b + det)/(2*a);
root2 = (-b - det)/(2*a);
Display(root1, root2);
}
void Display(float root1, float root2)
{
printf("The first root is %0.2f \n",root1);
printf("The second root is %0.2f \n",root2);
}