Sie sind auf Seite 1von 4

Computer Programming Abdullah Abdul Wahid 02-134192-015

Computer Programming [Theory]


Task 1: Create a login function, that would login at the correct input.
Apply 2 Conditions as follows:
1) Username must not have any special characters
2) Password must be hidden (*) on the screen.
Code:
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
char fbLogin(string uID, char pass[10]); //step 1
int main()
{
char pass[10] = { 0 };
string uID;

fbLogin(uID,pass);

char fbLogin(string uID, char pass[10]) //step 2


{
bool accepted = false;
while (!accepted)
{
accepted = true;
cout << "\nEnter authorised Username : ";
cin >> uID;
for (int i = 0; i < uID.length(); i++)
{
if (!isalpha(uID[i]))
{
accepted = false;
cout << "\nPlease don't use special string characters \n";
break;
}

}
}
if (accepted = true)
{
char temp;
cout << "Enter password (length must be <=10): ";
for (int i = 0; i < 10; i++)
{
char temporary;
temporary = _getch();
_putch('*');
if (temporary == 13)
break;
else
pass[i] = temporary;
Computer Programming Abdullah Abdul Wahid 02-134192-015

}
cout << "\n";
if (uID == "AbdullahAW" && !strcmp(pass, "paki12"))
{
cout << "Welcome, Login Authorised! \n";
}
else
{
cout << "Login Failed! Please try again. \n";
}
}
return 0;
}

Output:

Task 2: Create 4 functions each of the following types:


1) No Return, No Parameter/Argument
2) No Return, Yes Parameter/Argument
3) Yes Return, No Parameter/Argument
4) Yes Return, Yes Parameter/Argument
Code:
void Printing();
void Multiply(int num1, int num2);
float Divide();
char Grade(int marks);
int main()
{
int num1 = 45, num2 = 33, marks=75;
float dividant;
char Grd;
Printing();
Computer Programming Abdullah Abdul Wahid 02-134192-015

Multiply(num1, num2);
dividant = Divide();
cout << "Division of " << num1 << " & " << num2 << " is " << dividant << "\n";
Grd = Grade(marks);
cout << "Grade obtained at marks " << marks << " out of 100 is : " << Grd <<
"\n";
}

void Printing()
{
cout << "================================= \n";
cout << "TYPE 1: NO Return, NO Parameters! \n";
cout << "================================= \n";
int sum;
cout << "Maths is fun! \n";
sum = 2 + 2;
cout << "Sum of 2 + 2 =" << sum;
return;
}

void Multiply(int num1, int num2)


{
cout << "\n================================= \n";
cout << "TYPE 2: NO Return, Yes Parameters! \n";
cout << "================================= \n";
int Multiply = num1*num2;
cout << "Multiplication of " << num1 << " & " << num2 << " is " << Multiply <<
"\n";
return;
}

float Divide()
{
int num1 = 45, num2 = 33;
cout << "================================= \n";
cout << "TYPE 3: YES Return, NO Parameters! \n";
cout << "================================= \n";
float Div = (float)num1 / (float)num2;
return Div;
}

char Grade(int marks)


{
char Gr;
cout << "================================== \n";
cout << "TYPE 4: YES Return, YES Parameters! \n";
cout << "================================== \n";
if (marks > 90)
Gr = 'A';
else if (marks > 80)
Gr = 'B';
else if (marks > 70)
Gr = 'C';
else if (marks > 60)
Gr = 'D';
else if (marks > 50)
Gr = 'F';
else
Gr = 'U';
return Gr;
}
Computer Programming Abdullah Abdul Wahid 02-134192-015

Output:

Das könnte Ihnen auch gefallen