BTC USD 83,357.6 Gold USD 4,105.67
Time now: Jun 1, 12:00 AM

C++ Programming

#include <iostream>
#include <fstream>
#include <windows.h>
#define size 50

using namespace std;

struct Books
{
string call_numbers;
string title;
string author;
string publication;
};
Books temp;
Books Book[50];

int book=0;

char ID[size], password[size], TYPE[size], PASSWORD[size];
int create_login(char[],char[]);

void login();
void sort(int);
void searching_title();
void searching_author();

int create_login(char ID[],char password[])
{
ifstream new_account("new_account.txt");

while(new_account >> TYPE >> PASSWORD)
{

if(!strcmp(TYPE,ID) && !strcmp(PASSWORD,password))
{
cout << "\n\n\t\t\tLogin successfully.\n\n\t\t\t";
system ("PAUSE");
return 0;
}
else
{
cout << "\n\n\t\t\tPlease register before log in.\n\n\t\t\t";
system ("PAUSE");
login();
return 0;
}
}
}

void login()
{
int x;

do{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tPress 1 for log in\n\n";
cout << "\n\t\t\tPress 2 for sign up\n\n";
cout << "\n\t\t\tOption : ";
cin >> x;

ofstream new_account("new_account.txt", ios :: in);

switch(x)
{
case 1:
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tLogin ID : ";
cin >> ID;
cout << "\n\t\t\tPassword : ";
cin >> password;
create_login(ID, password);
break;
case 2:
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tPlease fill in the information.\n";
cout << "\n\t\t\tLogin ID : ";
cin >> ID;
new_account << ID << endl;
cout << "\n\t\t\tPassword : ";
cin >> password;
new_account << password << endl;
cout << "\n\t\t\tSign up sucessful\n\t\t\t";
system("PAUSE");
login();
break;
default:
cout << "\n\n\t\t\tPlease enter a valid number!\n\t\t\t";
system( "pause" );
break;
}
}while (x!=1);
}

void sort(int a = 1)
{
string empty;
ifstream open("books.txt");
int j;

while (!(open.eof()))
{
getline (open,temp.call_numbers);
getline (open,temp.title);
getline (open,temp.author);
getline (open,temp.publication);
getline (open,empty);

if (a == 1)
{
for (j = book; j > 0 ; j-- )
{if (Book[j-1].title <= temp.title)
break;
Book[j]= Book[j-1];
}
Book[j] = temp;
}
else if (a == 2)
{
for (j = book; j > 0 ; j-- )
{if (Book[j-1].author <= temp.author)
break;
Book[j]= Book[j-1];
}
Book[j] = temp;
}
book ++;
}
if (book==0)
{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\n\t\t\tNo records\n\t\t\t";
system ("PAUSE");
}
else
{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;

if (a == 1)
{cout << "\nThe books in library(sort by title) are:\n";
for (int i=0;i<book;i++)
{
cout << "********************************************************************************"<<endl;
cout << "Number\t\t:" << i+1 << endl;
cout << Book.title << endl ;
cout << Book.call_numbers<< endl;
cout << Book.author<<endl;
cout << Book.publication<<"\n\n";
cout << "********************************************************************************"<<endl;
}
cout << "\n\n\t\t\t ---Search by title--- \n\n";
searching_title();
cout << "\n\t\t\t";
system("PAUSE");
}
else if (a == 2)
{
cout << "\nThe books in library(sort by author) are:\n";
for (int i=0;i<book;i++)
{
cout << "********************************************************************************"<<endl;
cout << "Number\t\t:" << i+1 << endl;
cout << Book.author<<endl;
cout << Book.title << endl ;
cout << Book.call_numbers<< endl;
cout << Book.publication<<"\n\n";
cout << "********************************************************************************"<<endl;
}
cout << "\n\n\t\t\t ---Search by author--- \n\n";
searching_author();
cout << "\n\t\t\t";
system("PAUSE");
}
else
cout << "\n\t\t\t ---Program End---\n";
cout << "\n\t\t\tThank you and have a nice day!";
}
book = 0;
}

void searching_title()
{
ifstream count("books.txt");

string bookdata,topic, kill;
cout << "\tInput title to be search : ";
cin >> topic;
cout << endl;

int c=1;

while(getline(count, kill))
c++;

ifstream list2("books.txt");
int control = 2;
for (int b=1; b<=c; b++)
{
getline(list2, bookdata);
if(b == control){

{
const int length = bookdata.length();
for(int i=0; i!=length; ++i)
bookdata = tolower(bookdata);
}
{
const int length = topic.length();
for(int i=0; i!=length; ++i)
topic = tolower(topic);
}

if(bookdata.rfind(topic, 100) != string::npos)
cout << "\t" << bookdata << endl;
control = control+5;
}
}
cout << "\n\t\t\t ---End of list---\n";
}

void searching_author()
{
ifstream count2("books.txt");
int c2=1;

string data,writer, killing;
cout << "\tInput word to be search : ";
cin >> writer;
cout << endl;

while(getline(count2, killing))
c2++;

ifstream list("books.txt");
int control2 = 3;
for (int z=1; z<=c2; z++)
{
getline(list, data);
if(z == control2){
{
const int length = data.length();
for(int i=0; i!=length; ++i)
data = tolower(data);
}
{
const int length = writer.length();
for(int i=0; i!=length; ++i)
writer = tolower(writer);
}
if(data.rfind(writer, 29) != string::npos)
cout << "\t" << data << endl;
control2 = control2+5;
}
}
cout << "\n\t\t\t ---End of list---\n";
}

int main()
{
login();
int a;
while(a==1||a==2)
{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tPress 1 for searching by title\n\n";
cout << "\n\t\t\tPress 2 for searching by author\n\n";
cout << "\n\t\t\tPress any key for exit\n\n";
cout << "\n\t\t\tOption : ";
cin >> a;
sort(a);
}
cout << "\n\t\t\t";
system("PAUSE");
return 0;
}
 
weh pion ko pi curi programming library UPM ker:eek:
 
ape la agak2nye hasil progam tu ye...:D

kot2 undefined ero........


:eek: :eek: :eek: :eek:
 
C++..perghh..semua subjek programming aku amik 3kali.Bengap nak mampus aku nih.~X(

rase kelakar bila aku nak pikirkan kenangan zaman2 wat koding nih..Penah skali,aku sanggup escape time test.balik umh suh member aku buatkan...hahaha..:))
 
stack benda paling menyampah dlm C..
satu hape pun tak paham nak bg susun betui2...
C++ = C+ ....
 
#include <iostream>
#include <fstream>
#include <windows.h>
#define size 50

using namespace std;

struct Books
{
string call_numbers;
string title;
string author;
string publication;
};
Books temp;
Books Book[50];

int book=0;

char ID[size], password[size], TYPE[size], PASSWORD[size];
int create_login(char[],char[]);

void login();
void sort(int);
void searching_title();
void searching_author();

int create_login(char ID[],char password[])
{
ifstream new_account("new_account.txt");

while(new_account >> TYPE >> PASSWORD)
{

if(!strcmp(TYPE,ID) && !strcmp(PASSWORD,password))
{
cout << "\n\n\t\t\tLogin successfully.\n\n\t\t\t";
system ("PAUSE");
return 0;
}
else
{
cout << "\n\n\t\t\tPlease register before log in.\n\n\t\t\t";
system ("PAUSE");
login();
return 0;
}
}
}

void login()
{
int x;

do{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tPress 1 for log in\n\n";
cout << "\n\t\t\tPress 2 for sign up\n\n";
cout << "\n\t\t\tOption : ";
cin >> x;

ofstream new_account("new_account.txt", ios :: in);

switch(x)
{
case 1:
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tLogin ID : ";
cin >> ID;
cout << "\n\t\t\tPassword : ";
cin >> password;
create_login(ID, password);
break;
case 2:
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tPlease fill in the information.\n";
cout << "\n\t\t\tLogin ID : ";
cin >> ID;
new_account << ID << endl;
cout << "\n\t\t\tPassword : ";
cin >> password;
new_account << password << endl;
cout << "\n\t\t\tSign up sucessful\n\t\t\t";
system("PAUSE");
login();
break;
default:
cout << "\n\n\t\t\tPlease enter a valid number!\n\t\t\t";
system( "pause" );
break;
}
}while (x!=1);
}

void sort(int a = 1)
{
string empty;
ifstream open("books.txt");
int j;

while (!(open.eof()))
{
getline (open,temp.call_numbers);
getline (open,temp.title);
getline (open,temp.author);
getline (open,temp.publication);
getline (open,empty);

if (a == 1)
{
for (j = book; j > 0 ; j-- )
{if (Book[j-1].title <= temp.title)
break;
Book[j]= Book[j-1];
}
Book[j] = temp;
}
else if (a == 2)
{
for (j = book; j > 0 ; j-- )
{if (Book[j-1].author <= temp.author)
break;
Book[j]= Book[j-1];
}
Book[j] = temp;
}
book ++;
}
if (book==0)
{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\n\t\t\tNo records\n\t\t\t";
system ("PAUSE");
}
else
{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;

if (a == 1)
{cout << "\nThe books in library(sort by title) are:\n";
for (int i=0;i<book;i++)
{
cout << "********************************************************************************"<<endl;
cout << "Number\t\t:" << i+1 << endl;
cout << Book.title << endl ;
cout << Book.call_numbers<< endl;
cout << Book.author<<endl;
cout << Book.publication<<"\n\n";
cout << "********************************************************************************"<<endl;
}
cout << "\n\n\t\t\t ---Search by title--- \n\n";
searching_title();
cout << "\n\t\t\t";
system("PAUSE");
}
else if (a == 2)
{
cout << "\nThe books in library(sort by author) are:\n";
for (int i=0;i<book;i++)
{
cout << "********************************************************************************"<<endl;
cout << "Number\t\t:" << i+1 << endl;
cout << Book.author<<endl;
cout << Book.title << endl ;
cout << Book.call_numbers<< endl;
cout << Book.publication<<"\n\n";
cout << "********************************************************************************"<<endl;
}
cout << "\n\n\t\t\t ---Search by author--- \n\n";
searching_author();
cout << "\n\t\t\t";
system("PAUSE");
}
else
cout << "\n\t\t\t ---Program End---\n";
cout << "\n\t\t\tThank you and have a nice day!";
}
book = 0;
}

void searching_title()
{
ifstream count("books.txt");

string bookdata,topic, kill;
cout << "\tInput title to be search : ";
cin >> topic;
cout << endl;

int c=1;

while(getline(count, kill))
c++;

ifstream list2("books.txt");
int control = 2;
for (int b=1; b<=c; b++)
{
getline(list2, bookdata);
if(b == control){

{
const int length = bookdata.length();
for(int i=0; i!=length; ++i)
bookdata = tolower(bookdata);
}
{
const int length = topic.length();
for(int i=0; i!=length; ++i)
topic = tolower(topic);
}

if(bookdata.rfind(topic, 100) != string::npos)
cout << "\t" << bookdata << endl;
control = control+5;
}
}
cout << "\n\t\t\t ---End of list---\n";
}

void searching_author()
{
ifstream count2("books.txt");
int c2=1;

string data,writer, killing;
cout << "\tInput word to be search : ";
cin >> writer;
cout << endl;

while(getline(count2, killing))
c2++;

ifstream list("books.txt");
int control2 = 3;
for (int z=1; z<=c2; z++)
{
getline(list, data);
if(z == control2){
{
const int length = data.length();
for(int i=0; i!=length; ++i)
data = tolower(data);
}
{
const int length = writer.length();
for(int i=0; i!=length; ++i)
writer = tolower(writer);
}
if(data.rfind(writer, 29) != string::npos)
cout << "\t" << data << endl;
control2 = control2+5;
}
}
cout << "\n\t\t\t ---End of list---\n";
}

int main()
{
login();
int a;
while(a==1||a==2)
{
system( "cls" );
cout << "\n********************************************************************************"<<endl;
cout << "\t\t\tWelcome to UPM Library System!"<<endl;
cout << "\n********************************************************************************\n"<<endl;
cout << "\n\t\t\tPress 1 for searching by title\n\n";
cout << "\n\t\t\tPress 2 for searching by author\n\n";
cout << "\n\t\t\tPress any key for exit\n\n";
cout << "\n\t\t\tOption : ";
cin >> a;
sort(a);
}
cout << "\n\t\t\t";
system("PAUSE");
return 0;
}


pion nie coding pasal apa?.....output dia camner?....ko punya ker nie??
 
pion window.h nie dia bleh cari kat mana dlm web nie?...apa kegunaan dia?
 
Fuh...sapa2 masta C++ nih leh main dengan Sun Solaris/Linux OS nih...Takper belajar slow2. Aku memang kurengzz ngan C++ nih. Kalo takat open source programming leh la...copy & paste. Huhuhuhu...
 
Back
Top
Log in Register