Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

ASSIGNMENT

IN COMP2 &
COMP3
Submitted by:
Alonsagay, Jeffrey Ryan
Abude, Floriza
Linatoc, Geneva
Loyola, Hanna Fey
(CED-01-401A)

Submitted to:
Dr. Arlene Grace Diaz
1. Write a program that would input a password and test if the password
entered is correct and display the “Password Accepted!!!” otherwise display
“Invalid Password!!!”, if an incorrect password is entered three times, the
message “Account is Blocked!!!” will appear.

CODE:

#include<iostream.h>
// c++ program that will input password and test whether if it is correct or
incorrect.

int main()
{
// declaration of variables
int pass, ctr=1;

// while loop and if-else condition


while(ctr<=3)
{
ctr++;
cout<<"\n\n\t\t\tEnter Password: ";
cin>>pass;
if(pass==1234){
cout<<"\n\t\t\tPassword Accepted!!!";
return 0;
} else {
cout<<"\n\t\t\tInvalid Password!!!";
}

}
cout<<"\n\n\t\t\tAccount is Blocked!!!";
return 0;
}
SCREENSHOT:
2. Write a program that would input the following data: Student Name,
Average, Tuition Fee and print the Total Tuition Fee where

Total Tuition Fee = Tuition Fee – Discount

Use the table below to determine the discount:

Average Discount
95-100 100%
90-94 50%
85-89 25%
84-below 0

CODE:

#include<iostream.h>
// c++ program that will input the student name, average, tuition fee and print
the total tuition fee.

int main()
{
// declaration of variables
char name [100];
int ave, tuition, totalfee, discount;

cout<<"\n\n\n\t\t\tEnter Student Name: ";


cin>>name;
cout<<"\n\t\t\tEnter Average: ";
cin>>ave;
cout<<"\n\t\t\tEnter Tuition: ";
cin>>tuition;

// if-else condition
if(ave>=95 && ave<=100){
discount = tuition *.100;
totalfee = tuition - discount;
cout<<"\n\n\t\t\tYour Total Tuition Fee is: "<<totalfee;

}else if(ave>=90 && ave<=94){


discount = tuition *.50;
totalfee = tuition - discount;
cout<<"\n\n\t\t\tYour Total Tuition Fee is: "<<totalfee;

}else if(ave>=85 && ave<=89){


discount = tuition *.25;
totalfee = tuition - discount;
cout<<"\n\n\t\t\tYour Total Tuition Fee is: "<<totalfee;

} else {
discount = tuition *.0;
totalfee = tuition - discount;
cout<<"\n\n\t\t\tYour Total Tuition Fee is: "<<totalfee;

return 0;
}

SCREENSHOT:
3. Write a program that would accept two numbers and a character based
on the selection below, otherwise display “Invalid Input!!!” and ask the user
to try again. After accepting the character, the program will perform the
specified arithmetic operation and the answer will be displayed.

Sample output:

First Number: 7
Second Number: 7

<+> Addition
<-> Subtraction
<*> Multiplication
</> Division

Enter choice: *
The answer is 28

CODE:
#include<iostream.h>
// c++ program that will accept two numbers and make the user choose the
arithmetic operation.

int main()
{
// declaration of variables
int num1, num2;
char operation;
cout<<"\n\n\t\tEnter first number: ";
cin>>num1;
cout<<"\n\t\tEnter second number: ";
cin>>num2;
cout<<"\n\n\t\tPlease choose an operation.";
cout<<"\n\n\t\t<+> Addition";
cout<<"\n\t\t<-> Subtraction";
cout<<"\n\t\t<*> Multiplication";
cout<<"\n\t\t</> Division";
cout<<"\n\n\t\tEnter choice: ";
cin>>operation;

// switch
switch(operation)
{
case '+': cout<<"\n\n\t\tThe Answer is: "<<num1+num2;break;
case '-': cout<<"\n\n\t\tThe Answer is:"<<num1-num2;break;
case '*': cout<<"\n\n\t\tThe Answer is:"<<num1*num2;break;
case '/': cout<<"\n\n\t\tThe Answer is:"<<num1/num2;break;
default: cout<<"\n\n\t\tInvalid Input! Please Try Again.";
}

return 0;
}
SCREENSHOT:

You might also like