Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Data Structure & Algorithm

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

#include <iostream>

#include <cmath>

#include <cstdlib>

using namespace std;

// Function declarations

void calculator();

void pattern();

void intro();

// Global variables

int b, c;

double fnum, snum;

char opp;

int main() {

intro();

int num;

do {

c = 1;

cout << "\n\n";

cout << " Press 1 for a Calculator :\n";

cout << " Press 2 for displaying Pattern :\n";

cout << "**\n";

cout << "- ";

cin >> num;


switch (num) {

case 1:

calculator();

break;

case 2:

pattern();

break;

default:

cout << "\n";

cout << "Incorrect Choice. Please try again from 1 and 2.\n";

} while (c == 1);

return 0;

void calculator() {

do {

cout << "\n";

cout << "Enter the First Number: ";

cin >> fnum;

cout << "Enter the Operator (+, -, *, /, ^): ";

cin >> opp;

if (opp == '^') {

cout << "Enter the Exponent: ";

cin >> snum;

} else {
cout << "Enter the Second Number: ";

cin >> snum;

switch (opp) {

case '+':

cout << fnum << " + " << snum << " = " << fnum + snum << "\n";

break;

case '-':

cout << fnum << " - " << snum << " = " << fnum - snum << "\n";

break;

case '*':

cout << fnum << " * " << snum << " = " << fnum * snum << "\n";

break;

case '/':

if (snum != 0) {

cout << fnum << " / " << snum << " = " << fnum / snum << "\n";

} else {

cout << "Error: Division by zero.\n";

break;

case '^':

cout << fnum << " ^ " << snum << " = " << pow(fnum, snum) << "\n";

break;

default:

cout << "\n";

cout << "Incorrect Operator Entry. Please choose from +, -, *, /, and ^.\n";

}
cout << "\n";

cout << "***\n";

cout << "\tPress 1 to go to Main Menu.\n";

cout << "\tPress 2 to go Back.\n";

cout << "###\n";

cout << "..... ";

cin >> c;

} while (c == 2);

void pattern() {

do {

cout << "Press 1 for Pattern 1:\n";

cout << "Press 2 for Pattern 2:\n";

cin >> b;

switch (b) {

case 1:

for (int i = 1; i <= 5; i++) {

for (int j = 1; j <= i; j++)

cout << "* ";

cout << "\n";

break;

case 2:

// Implement Pattern 2 logic here

break;

default:
cout << "Wrong Pattern Number Entry.\n";

} while (c == 2);

void intro() {

string username = "admin";

string password = "password";

string inputUsername, inputPassword;

do {

system("cls");

cout << "\n\n\t\tPLEASE ENTER A USERNAME AND PASSWORD\n";

cout << "\t\tUSER NAME: ";

cin >> inputUsername;

cout << "\t\tPASSWORD: ";

cin >> inputPassword;

if (inputUsername == username && inputPassword == password) {

system("cls");

cout << "\n\n\t\tLogin successful.\n\n";

break;

} else {

cout << "\n\n\t\tLogin unsuccessful. Try again.\n\n";

system("pause");

} while (true);
}

You might also like