Lab 8
Lab 8
Lab 8
LAB # 8
SUBMITTED BY: IRTAZA ALI NASIR
200901099
Q NO 1.A parking garage charges a $2.00 minimum fee to park for up to
three hours and an additional $1 per hour for each hour or part thereof over
four hours. The maximum charge for any given 24-hour period is $10.00.
Assume that no car parks for longer than 24 hours at a time. Write a program
that will calculate and print the parking charges for each of three customers
who parked their cars in this garage yesterday. You should enter the hours
parked for each customer. Your program should print the results in a neat
tabular format, and should calculate and print the total of yesterday's
receipts. The program should use the function calculate Charges to determine
the charge for each customer.
ASSINGED PROGRAM
#include <iostream>
using namespace std;
int main()
{
int customer;
float one;
float two;
float three = 0;
float hours;
if (customer == 1)
one = hours;
else if (customer == 2)
two = hours;
else
three = hours;
}
cout << "\n" << "Car" << "\t""Hours" << "\t""Charge";
cout << "\n" << 1 << "\t" << one << "hr" "\t" << calculateCharges(one) << "$";
cout << "\n" << 2 << "\t" << two << "hr" "\t" << calculateCharges(two) << "$";
cout << "\n" << 3 << "\t" << three << "hr" "\t" << calculateCharges(three) << "$";
cout << "\n" << "TOTAL""\t" << one + two + three << "hr" "\t" <<
calculateCharges(one) + calculateCharges(two) + calculateCharges(three) << "$";
}
RESULT ON SECREEN
Q 2. The use of computers in education is referred to as computer-assisted
instruction (CAI). Write a program that will help an elementary school
student learn multiplication. Use the rand function to produce two positive
one-digit integers. These two rand generated integers must be pass to the
function named “Result Checking”. The function should then prompt the user
with a question, such as How much is 6 times 7? The student then inputs the
answer. Next, the program checks the student’s answer. If it’s correct, the
function will return 1 or true if it is false the function will return 0 to false. In
the main you must display the message "Very good!" if the answer is correct
and ask another multiplication question. If the answer is wrong, display the
message "No. Please try again." and let the student try the same question
repeatedly until the student finally gets it right. The function “Result
Checking” should be called once when the application begins execution and
each time the user answers the question correctly.
ASSINGED PROGRAM
#include<iostream>
using namespace std;
void result_checking();
int main()
{
result_checking();
return 0;
}
void result_checking() {
int x, y, answer = 0;
cout << "enter a number" << endl;
RESULT ON SECREEN
Q3: Write a C program that will calculate the product of two matrixes and
print the resultant matrix.
ASSINGED PROGRAM
#include <iostream>
using namespace std;
int main()
{
int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;
cout << "ENTER ROWS AND COLOUMN OF Ist MATRIX " << endl;;
cin >> r1 >> c1;
cout << "ENTER ROWS AND COLOUMN OF 2nd MATRIX " << endl;
cin >> r2 >> c2;
while (c1 != r2)
{
cout << "MATH ERROR PLZ CHEK YOUR INPUTS AND TREY AGAIN." << endl;;
cout << "PLZ ENTER ROWS AND COLOUMN OF FIRST MATRIX " << endl;
cin >> r1 >> c1;
cout << "PLZ ENTER ROWS AND COLOUMN OF SECOND MATRIX: " << endl;
cin >> r2 >> c2;
}
cout << endl << "ENTER VALUES OF MATRIX 1:" << endl;
for (i = 0; i < r1; ++i)
for (j = 0; j < c1; ++j)
{
cout << "ENTER ELEMENTS a" << i + 1 << j + 1 << " : ";
cin >> a[i][j];
}
cout << endl << "ENTER SECOND MATRIX :" << endl;
for (i = 0; i < r2; ++i)
for (j = 0; j < c2; ++j)
{
cout << "ENTER ELEMENTS b" << i + 1 << j + 1 << " : ";
cin >> b[i][j];
}
for (i = 0; i < r1; ++i)
for (j = 0; j < c2; ++j)
{
mult[i][j] = 0;
}
for (i = 0; i < r1; ++i)
for (j = 0; j < c2; ++j)
for (k = 0; k < c1; ++k)
{
mult[i][j] += a[i][k] * b[k][j];
}
cout << endl << "Output Matrix: " << endl;
for (i = 0; i < r1; ++i)
for (j = 0; j < c2; ++j)
{
cout << " " << mult[i][j];
if (j == c2 - 1)
cout << endl;
}
RESULT ON SECREEN
Q 4 Design then implement a C++ program that will produce transpose of
given matrix and print it along with the original one.
ASSINGED PROGRA
#include <iostream>
using namespace std;
int main()
{
}
cout << "NOW HERE TRANSPOSE IS" << endl;
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 5; j++)
{
cout << mat[i][j] << "\t";
}
cout << endl;
}
RESULT ON SECREEN