0% found this document useful (0 votes)
27 views16 pages

ISOM3029 Assi1

Uploaded by

selena.shi.jw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views16 pages

ISOM3029 Assi1

Uploaded by

selena.shi.jw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Student Name: Adelyn, HE JIAQI

Student ID: BC004997


Session Number: ISOM3029-001

Evaluation Table

Criteria Percentage Q.1 Q.2 Q.3


Workable Program
30%
- sample input & output
30%
- uploaded program code
20%
- no errors of any type
Program Readability (easy to understand,
15%
internal comments, etc.)
Your own suggestions 5%
Bonus: Additional features (e.g. error
5%
handling, more efficient way, etc.)
Total: 105%
1.Reverse Program

Program:
// Program description:
//1.The program solved: Reverse a positive three-digit integer number.
//2.Limitation: It makes the program a little bit long. because before it comes to the
while loop, it reverse the number for one time.
//And if I enter a character instead of three-digit integer number, it will run without
stopping.

#include <iostream>

using namespace std;


int main()
{
int rem;
int number3;
int number2;
int number1;
int number;
char A;
//Welcome the user to the Reverse Program
cout << "Welcome to the Reverse Program!\n";

//Prompt the user to input a positive three-digit number


cout << "\nPlease enter a positive three-digit number: ";
cin >> number;

//Calculate the reverse number


if (number>99 && number <1000)
{
rem = number % 100;
number3 = number / 100;
number2 = rem / 10;
number1 = rem % 10;
//Display the result
cout << "The reversed form of " << number << " is " << number1 << number2
<< number3 << ".\n";
//Prompt the user to choose whether to continue
cout << "Would you like to continue(Y for Yes, N for No)? ";
}
//Error-checking: If the user doesn't input a positive three-digit number, display the
error
else
{
cout << "Your input is invalid! No reversed form is done!\n";
//Prompt the user to choose whether to continue
cout << "Would you like to continue(Y for Yes, N for No)? ";
}

cin >> A;
//While the user input Y, calculate the reverse number
while (A == 'Y')
{
cout<< "+++++++++++++++++++++++++++++++++++++++++++
+++++++++\n"<<" \n";
cout << "Please enter a positive three-digit number:" ;
int number;
cin >> number;

if (number > 99 && number < 1000)


{
rem = number % 100;
number3 = number / 100;
number2 = rem / 10;
number1 = rem % 10;
//Display the result
cout << "The reversed form of " << number << " is " << number1 <<
number2 << number3 << ".\n" << "Would you like to continue(Y for Yes, N for No)? ";
cin >> A;
}
//Error-checking: If the user doesn't input a positive three-digit number, display
the error
else
{
cout << "Your input is invalid! No reversed form is done!\n" << "Would you
like to continue(Y for Yes, N for No)? ";
cin >> A;
}

}
//If user input N, end the program
if (A == 'N')
{
cout << "+++++++++++++++++++++++++++++++++++++++++++
+++++++++\n" << " \n";
cout << "Thank you very much!";
}

//Error-checking: If the user doesn't input Y or N, display error


else
cout << "Your input is error, you should input Y or N. Please run the program
again!" << endl;
return 0;
}

Suggestion:

1. It is hard for me to do the reverse number in a short time, and I have to search on the Internet
to know about some other information.
2. I used the A=’Y’ as a condition of continue the reverse program. But it failed. And then I
found that I should use the A= =’Y’, because Y is a character and “=”is used not as a equal
sign in C++.
3. I learnt the row in the sample output comes from the add signs“ +”
4. I learnt how to calculate the reverse number of a three-digit number.
5. I learnt how to use the while loop to make the program continue again.
6. I don’t want this question in my exam because the time of the exam is limited. But this
assignment takes me a long time to finish.
7. I learnt how to use “\n” to start a new line and make the output of program clearly.

Additional features:Error handling


In addition to the error checking required by the assignment, I do the error checking when prompt
the user to choose to continue or not.
//Error-checking: If the user doesn't input Y or N, display error
else
cout << "Your input is error, you should input Y or N. Please run the program
again!" << endl;

Program sample input and output:


2. Personal Loan System
Program:
// Program description:
//1.The program solved: Using the input value of the amount of the personal loan, the
annual interest rate charged by the bank, and the monthly payment of the customer
// Display the duration of a loan, monthly current face value of the loan, the monthly
interest payment and the repaid principal in a table.

#include <iostream>
#include<iomanip>
using namespace std;

int main()
{
int loan;
double rate;
int payment;
int months;
double fvalue;
double interest;
double repaid;
//Welcome the user to the Personal Loan System
cout << "Welcome to the Personal Loan System\n" ;
cout << "===================================\n";
//Prompt the user to enter the loan amount
cout << "\nPlease enter the loan amount : ";
cin >> loan;
//Prompt the user to enter the annual interest rate
cout << "Please enter the annual interest rate(%) : " ;
cin >> rate;
//Prompt the user to enter the monthly payment
cout << "Please enter the monthy payment : " ;
cin >> payment;
//Error-checking:If user input any negative number of loan,rate or payment,
display error
if (loan < 0 || rate < 0 || payment < 0)
cout << "\nError! You should input non-negative number of loan,rate and
payment!" << endl;
else
{
//Print the table body
cout <<"\n" << setw(5) << "Month" << setw(26) << "Current face
value" << setw(12) << "Interest" << setw(20) << "Repaid Principal" << endl;
cout <<
"===================================================
===========\n";
//Calculate the month, current face value, interest and repaid principal
months = 1;
fvalue = loan;
interest = fvalue * rate / 1200;
repaid = payment - interest;

while (fvalue > payment)


{
cout <<fixed<<setprecision(2)<< setw(4) << months << setw(12)
<< "$" << setw(9) << fvalue << setw(12) << "$" << setw(6) << interest <<
setw(5) << "$" << setw(8) << repaid << endl;
months = months + 1;
fvalue = fvalue - repaid;
interest = fvalue * rate / 1200;
repaid = payment - interest;

}
//Display the result
cout << "Remaining Balance in month " << months << "= " << "$" <<
fvalue << endl;
cout << "(Note: The remaining balance " << "$" << fvalue << " will be
settled in the last month!)" << endl;

}
return 0;
}

Suggestion:

1. It is hard for me to work out the interest and repaid formula in a short time, and I have to
search on the Internet to know about some other information.
2. I initially set the limitation of while is” face value>0”, but it always output the result of the
face value of month 121. It takes me a long time to think about this and I finally found I
should change the limitation into “face value>monthly payment”.
3. In the beginning, I use the “static_cast” to make the result in a two decimal number, but it
shows if the result is an integer, it will not display “.00”, so I change it to the
“setprecision(2)” to keep the decimal number 0.
4. I learnt how to make a table which looks similar to the requirement of assignment by using
“setw()”.
5. I learnt the row in the sample output comes from the add signs“ +”
6. I learnt how to use the “||” to show the meaning of “or” in “if condition”.
7. I don’t want this question in my exam because the time of the exam is limited. But this
assignment takes me a long time to finish.
8. Application: I think this program can also be used by the students and teachers of GEST1001,
because the content of loan and interest is a part of this course.
9. I learnt how to use “\n” to start a new line and make the output of program clearly.

Additional features:Error handling


In addition to the error checking required by the assignment, I do the error checking when user
input any negative number of loan, rate or payment
//Error-checking:If user input any negative number of loan,rate or payment, display
error
if (loan < 0 || rate < 0 || payment < 0)
cout << "\nError! You should input non-negative number of loan,rate
and payment!" << endl;

Program sample input and output:


3. Monthly Payroll Program
Program:
// Program description:
//1.The program solved: Make a payroll system, calculate the monthly pay of four
kinds of worker: manager, hourly worker, commission worker, pieceworker, and print
the table of summary about the pay.
//2.Limitation: a.If we input "1000" after "Please enter the code (0 to stop) :", it will
output "Invalid input!" and the table instead of only "Invalid input!" and "Please enter
the code (0 to stop) :".
//b.If we input "1--"after "Please enter the code (0 to stop) :", it will output "Invalid
input!" and "Please enter the code (0 to stop) :" with three times instead of only one
time.
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
int n_Comm = 0;
double Cpay = 0;
double Gross_Monthly_Sale;
double cpay;
int n_Hour = 0;
double Hpay = 0;
double Hsalary;
double hours;
double hpay;
int n_Mana = 0;
double Mpay = 0;
double Msalary;
double mpay;
int n_Piece = 0;
double Ppay = 0;
double Psalary;
double number;
double ppay;
char L;
double Tpay;
//Welcome the user to the Monthly Payroll Program
cout << "Welcome to the Monthly Payroll Program\n";
cout << "======================================\n";
cout << "Employee Code:\nM = Manager, H = Hourly worker, C = Commission
worker, P = Pieceworker\n";
cout << " \n";
//Prompt the user to enter the employee code(0 to stop)
cout << fixed << setprecision(2) << "Please enter the code (0 to stop) :";
cin >> L;
while (L != '0')
//Calculate the pay of employee
{
if (L == 'C')
{
cout << "Commission worker selected!\nPlease enter the gross monthly sales:
";

cin >> Gross_Monthly_Sale;


cpay = 200 + 0.15 * Gross_Monthly_Sale;
Cpay = Cpay + cpay;
cout << "Commission worker's pay is $" <<Cpay<< endl;
cout << "\n";
n_Comm++;
cout << "Please enter the code(0 to stop) :";
cin >> L;
}
else if (L == 'H')
{
cout << "Hourly worker selected!\nPlease enter the hourly salary: ";
cin >> Hsalary;
cout << "Please enter the total hours worked: ";
cin >> hours;
if (hours <= 100)
hpay = hours * Hsalary;
else
hpay = 1.5 * (hours - 100) * Hsalary + 100 * Hsalary;
Hpay = Hpay + hpay;
cout << "Hourly worker's pay is $" << Hpay << endl;
cout << "\n";
n_Hour++;
cout << "Please enter the code(0 to stop) :";
cin >> L;
}
else if (L == 'M')
{
cout << "Manager selected!\nPlease enter the monthly salary: ";
cin >> Msalary;
mpay = Msalary;
Mpay = mpay + Mpay;
cout << "Manager's pay is $" << Mpay << endl;
cout << "\n";
n_Mana++;
cout << "Please enter the code(0 to stop) :";
cin >> L;
}
else if (L == 'P')
{
cout << "Pieceworker selected!\nPlease enter the salary per piece ($): ";
cin >> Psalary;
cout << "Please enter the number of pieces: ";
cin >> number;
ppay = Psalary * number;
Ppay = ppay + Ppay;
cout << "Pieceworker's pay is $" <<Ppay << endl;
cout << "\n";
n_Piece++;
cout << "Please enter the code(0 to stop) :";
cin >> L;
}
//Error-checking:If L is not equal to H,M,P or C, display error
else
{
cout << "Invalid input!\n";
cout << "\nPlease enter the code(0 to stop) :";
cin >> L;
}
}
//Display the result and print the table body when L=='0'
if (L == '0')
{
cout <<setw(45) << "Total number of employees" << setw(20) << "Total
payment\n";
cout <<
"═══════════════════════════════════════════════════════════════════════
════════\n";
cout << setw(8) << "Managers" << setw(19) << n_Mana << setw(25) << "$"
<< setw(7) << Mpay << endl;
cout << setw(14) << "Hourly workers" << setw(13) << n_Hour << setw(25) <<
"$" << setw(7) << Hpay << endl;
cout << setw(17) << "Commission workers" << setw(9) << n_Comm <<
setw(25) << "$" << setw(7) << Cpay << endl;
cout << setw(12) << "Pieceworkers" << setw(15) << n_Piece << setw(25) <<
"$" << setw(7) << Ppay << endl;
cout <<
"═══════════════════════════════════════════════════════════════════════
════════\n";
Tpay = Cpay + Mpay + Hpay + Ppay;
cout << setw(6) << "Total:" << setw(21) << n_Comm + n_Mana + n_Hour +
n_Piece << setw(25) << "$" << setw(7) << Tpay << endl;

return 0;
}
Suggestion:
1. I didn’t know how to make the program runs smoothly when enter two times of “C”. After
many trials and error, I finally succeeded in using “Cpay=cpay+Cpay”, and “nc++” to
increase the amount of commission worker’s pay in the final table. (The other workers’
problem was solved by the same way.)
2. I don’t want this question in my exam because the time of the exam is limited. But this
assignment takes me a long time to finish.
3. In the beginning, I use the “static_cast” to make the result in a two decimal number, but it
shows if the result is an integer, it will not display “.00”, so I change it to the
“setprecision(2)” to keep the decimal number 0.
4. I learnt how to make a table which looks similar to the requirement of assignment by using
“setw()”.
5. I learnt how to use “\n” to start a new line and make the output of program clearly.

Program sample input and output:

You might also like