Professional Documents
Culture Documents
ITPROG2
(Computer Programming 2 for IT)
ASSESSMENT
1
Character and String Manipulation
score
FUNCTION DESCRIPTION
strcpy(Target_String_Var,Src_String) Copies the C-string value Src_String into the C-string variable
Target_String_Var
strcpy(Target_String_Var,Src_String,limit) The same as the two argument strcpy except that at most Limit
characters are copied
strcat(Target_String_Var,Src_String) Concatenates the C-String value Src_String onto the end of C-string
in the C-string variable Target_String_Var
strcat(Target_String_Var,Src_String, Limit) The same as the two argument strcat except that at most Limit
characters are appended.
strlen(Src_String) Returns an integer equal to the length of Src_String. (The null
character, ‘\0’, is not counted in the length.
strcmp(String_1, String_2) Returns 0 if String_1 and String_2 are the same. Returns a value < 0
if String_1 is less than String_2. Returns a value > 0 if String_1 is
greater than String_2 (that is, returns a nonzero value if String_1
and String_2 are different). The order is lexicographic.
strcmp(String_1, String_2, Limit) The same as the two-argument strcmp except that at most Limit
characters are compared.
Character-Manipulating Functions
PROBLEM #1
Create a login module that uses either predefined or user-defined functions. User must be able to
create an account (sign up) and the program will ask for the user’s necessary information (i.e.
first name, last name, email, password).
Program specifications:
User must be able to login using the username and password declared during the creation
of his/her account.
The password must be equal or greater than 8 characters and must include letters and
numbers.
The password must have at least 1 uppercase letter.
User must be able to change his/her password. When changing his/her password, the
program should not accept the old password the user declared.
#include <iostream>
#include <fstream>
while (1)
{
cout<<"[Register/Login/Exit]\n"<<"Command:";
getline(cin,command);
if (command=="Exit")
{
return 1;
}
if (command=="Register")
{
ofstream g("registration.txt");
if (!g.is_open())
{
cout<<"Could Not Open File\n";
return 0;
}
cout<<"\n\n"<<"Enter a New Username:";
getline(cin, registerName);
cout<<"\nEnter New Password:";
getline(cin, registerPassword);
g<<registerName;
g<<"\n";
g<<registerPassword;
g.close();
}
if (command=="Login")
{
ifstream f("registration.txt");
if (!f.is_open())
{
cout<<"Could Not Open File\n";
return 0;
}
getline(f, name);
getline(f, password);
f.close();
while (1)
{
cout<<"\n\nEnter Your Username:";
getline(cin, inName);
cout<<"\nEnter Your Password:";
getline(cin,inPassword);
if (inName==name&& inPassword==password)
{
cout<<"You have Logged In
Successfully\n"<<"Welcome!"<<inName;
break;
}
cout<<"You Have Entered an Incorrect Username or Password\n";
}
}
cout<<"\n\n\n";
}
return 1;
}