COS1511 ASSIGNMENT 01
UNIQUE NUMBER: 830138
Question 1.
#include <iostream>
using namespace std;
int main()
{
int mFactor;
cout << "Please enter the factor to multiply the ingredients with :";
cin >> mFactor;
cout << "Recipe name" << endl;
cout << "\tIngredients" << endl;
cout << "\t\t" << 1*mFactor << " cups of all purpose flour" << endl;
cout << "\t\t" << 2*mFactor << " tablespoons of white sugar" << endl;
cout << "\t\t" << 2*mFactor << " teaspoons of baking powder" << endl;
cout << "\t\t" << 1*mFactor << " teaspoons of salt" << endl;
cout << "\t\t" << 1*mFactor << " egg" << endl;
cout << "\t\t" << 2*mFactor << " tablespoons of sunflower seed/olive oil" << endl;
cout << "\t\t" << 1*mFactor << " cups of milk" << endl;
cout << "\tMethod" << endl;
cout << "\t\tStep 1: Mix flour, sugar, baking powder and salt in a large bowl." << endl;
cout << "\t\tStep 2: Make a hole in the center of the bowl, which has all the mixed ingredients." <<
endl;
cout << "\t\tStep 3: Now pour the milk, beaten egg and oil in the centre of the bowl, and then mix
everything until it is smooth." << endl;
cout << "\t\tStep 4: Lightly pour oil on a frying pan, and heat the frying pan with medium high heat
on a stove." << endl;
cout << "\t\tStep 5: Pour/scoop the mixture on the frying pan, using approximately a quarter (1/4)
of a cup for each pancake." << endl;
cout << "\t\tStep 5: Flip then remove the pancake when it is brown on both sides (note: they
should not burn or turn black)" << endl;
cout << "\t\tStep 6: Recommend to SERVE WHILE IT IS HOT!!!" << endl;
return 0;
}
, Question 2.
#include <iostream>
using namespace std;
int main()
{
int nrPupils = 56, nrGroups, nrLeft, groupSize;
cout << "Please enter the size of each group: " << endl;
cin >> groupSize;
nrGroups = nrPupils/groupSize;
nrLeft = nrPupils - nrGroups*groupSize;
cout << "There are " << nrGroups << " groups consisting of " << groupSize << " pupils. There are "
<< nrLeft << " remaining pupils." << endl;
return 0;
}
Question 3.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float var1, var2;
char operation;
cout << "Please enter the first float value: ";
cin >> var1;
cout << "Please enter the second float value: ";
cin >> var2;
cout << "Please enter the operation required: ";
cin >> operation;
cout << setiosflags(ios::fixed) << setprecision(2);
if (operation == '+')
cout << "The sum of " << var1 << " and " << var2 << " is " << var1+var2 << endl;
else if (operation == '-')
cout << "The difference of " << var1 << " and " << var2 << " is " << var1-var2 << endl;
else if (operation == 'x')
cout << "The multiplication of " << var1 << " and " << var2 << " is " << var1*var2 << endl;
else if (operation == '/')
cout << "The division of " << var1 << " and " << var2 << " is " << var1/var2 << endl;
else if (operation == '%')
cout << "The modulus of " << var1 << " and " << var2 << " is " << (static_cast<int32_t>(var1))%
(static_cast<int32_t>(var2)) << endl;
UNIQUE NUMBER: 830138
Question 1.
#include <iostream>
using namespace std;
int main()
{
int mFactor;
cout << "Please enter the factor to multiply the ingredients with :";
cin >> mFactor;
cout << "Recipe name" << endl;
cout << "\tIngredients" << endl;
cout << "\t\t" << 1*mFactor << " cups of all purpose flour" << endl;
cout << "\t\t" << 2*mFactor << " tablespoons of white sugar" << endl;
cout << "\t\t" << 2*mFactor << " teaspoons of baking powder" << endl;
cout << "\t\t" << 1*mFactor << " teaspoons of salt" << endl;
cout << "\t\t" << 1*mFactor << " egg" << endl;
cout << "\t\t" << 2*mFactor << " tablespoons of sunflower seed/olive oil" << endl;
cout << "\t\t" << 1*mFactor << " cups of milk" << endl;
cout << "\tMethod" << endl;
cout << "\t\tStep 1: Mix flour, sugar, baking powder and salt in a large bowl." << endl;
cout << "\t\tStep 2: Make a hole in the center of the bowl, which has all the mixed ingredients." <<
endl;
cout << "\t\tStep 3: Now pour the milk, beaten egg and oil in the centre of the bowl, and then mix
everything until it is smooth." << endl;
cout << "\t\tStep 4: Lightly pour oil on a frying pan, and heat the frying pan with medium high heat
on a stove." << endl;
cout << "\t\tStep 5: Pour/scoop the mixture on the frying pan, using approximately a quarter (1/4)
of a cup for each pancake." << endl;
cout << "\t\tStep 5: Flip then remove the pancake when it is brown on both sides (note: they
should not burn or turn black)" << endl;
cout << "\t\tStep 6: Recommend to SERVE WHILE IT IS HOT!!!" << endl;
return 0;
}
, Question 2.
#include <iostream>
using namespace std;
int main()
{
int nrPupils = 56, nrGroups, nrLeft, groupSize;
cout << "Please enter the size of each group: " << endl;
cin >> groupSize;
nrGroups = nrPupils/groupSize;
nrLeft = nrPupils - nrGroups*groupSize;
cout << "There are " << nrGroups << " groups consisting of " << groupSize << " pupils. There are "
<< nrLeft << " remaining pupils." << endl;
return 0;
}
Question 3.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float var1, var2;
char operation;
cout << "Please enter the first float value: ";
cin >> var1;
cout << "Please enter the second float value: ";
cin >> var2;
cout << "Please enter the operation required: ";
cin >> operation;
cout << setiosflags(ios::fixed) << setprecision(2);
if (operation == '+')
cout << "The sum of " << var1 << " and " << var2 << " is " << var1+var2 << endl;
else if (operation == '-')
cout << "The difference of " << var1 << " and " << var2 << " is " << var1-var2 << endl;
else if (operation == 'x')
cout << "The multiplication of " << var1 << " and " << var2 << " is " << var1*var2 << endl;
else if (operation == '/')
cout << "The division of " << var1 << " and " << var2 << " is " << var1/var2 << endl;
else if (operation == '%')
cout << "The modulus of " << var1 << " and " << var2 << " is " << (static_cast<int32_t>(var1))%
(static_cast<int32_t>(var2)) << endl;