You are on page 1of 16

By

cout<<

TABLE OF CONTENTS | SLAM BOOK

CHAPTER 1 | PREFACE SECTION 1.1 SECTION 1.2 CERTIFICATE ACKNOWLEDGEMENT

2 2 2 3 3 4 5 10 12 12 12

CHAPTER 2 | THE PROJECT SECTION 2.1 SECTION 2.2 SECTION 2.3 SECTION 2.4 INTRODUCTION TO THE PROGRAM METHODOLOGY ADOPTED SOURCE CODE SCREEN SHOTS

CHAPTER 3 | BIBLIOGRAPHY SECTION 3.1 SECTION 3.2 REFRENCES LINKS

his is to certify that Punit Goswami of class 12th B has satisfactorily completed the project in Computer Science in the academic year 2012-13. I have examined the project and hereby accord my approval of it as a study carried out and presented in the manner required for its acceptance. This does not necessarily endorse or accept every statement made or opinion expressed or conclusion drawn, but only signifies the acceptance of the project for the purpose it is submitted for.

Mrs Shalini Singh Shalini Dixit PGT (Computer Science) Principal, K.V. Manauri

Dr

I hereby acknowledge my deep sense of gratitude and indebtedness to Mrs Shalini Singh, PGT (Computer Science) whose immense help, genius guidance, encouragement, 2

necessary suggestions, initiations, enthusiasm and inspiration made this work a master art and a joint enterprise.

Objective

Method

Code

INTRODUCTION
OBJECTIVE

1|ONE
1|ONE

Slam books are a personal memoir to the one which it belongs. It is filled by friends, close pals, near and dear ones. It not only gives brief information about them, like their phone no., email address or zodiac sign but it also lists what qualities they like in you and what would they wish for your future. Slam books are, more or less, a way to look back on the way people considered a person, in the form of the treasured memories.
TECHNICAL OVERVIEW 2|TWO

C++ can be used to build a program to build a system which emulates a slam book. Though it wont be visually much appealing, but the code line interface can be used to take the inputs and save them in a data file. Individual data entries can be saved as data objects and further modification can be allowed through distributing the program into suitable cohesive modules. To ensure providing the authority to eligible modifiers only, a token or a password could be supplied to every user who makes an entry. There should also be a way to see the data entries without making any new entry. Error handling steps should 3 also be dealt with, in case a faulty input is made by any novice user.

Henceforth, data entries will be referred to as Slams.

METHODOLOGY

2|TWO

The Slam Book program will use the input and output streams (i.e. iostream) to get the input from the user and to show the output to the user, respectively. The data file handling streams, i.e. fstream, ifstream and ofstream to save, access and modify the statically stored data. The static data will be stored in text files with .dat extension. In addition to these, predefined library files for handling strings (string.h & stdio.h), the exit controls (process.h) and for screen formatting (conio.h) will be used to make the program more appealing. The program would be distributed into five programs to do the different tasks in the program:

a) slamin( ) b) show( ) d) adios( ) e) main( )

to make a new slam. to show the previous slams. to ask for a final consent while exiting the program. to bind all the other functions.

c) modify( ) to let the user modify his/her slam.

Data structure with the name slam will be used to make a cohesive slam for a single user; another structure with the name date will be used to define dates. Loops will be used to provide a menu like interface in the main( ) function, which will further call the other functions to the respective jobs as mentioned above.

SOURCE CODE
/////////////////////////////////////////////// /// /// /////////////////////////////////////////////// #include<stdio.h> #include<process.h> #include<conio.h> #include<fstream.h> #include<string.h> struct date{int d,m,y;}; struct slam{ char name[36],nick[30],zodiac[15],hobbies[180], number[11],quals[200],l4u[300],email[50],addr[100]; char code[6]; date dob; }s1; void slamin(); void show(); void modify(); void adios(); void main() { char op; //to enter a new slam //to show older slams //to modify an old slam //to exit /// //// /// Slam Book Program // by Punit Goswami ///

THREE|3

cout<<"\n\n\n\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~$$$$$$$$$$$$$$$$$$$$$$$$~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~" <<"\n\t\t\t\v WELCOME TO MY SLAM BOOK!!! \v" <<"\n\t\t\t\t\t_-_ Punit Goswami \n\n"

<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~$$$$$$$$$$$$$$$$$$$$$$$$~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~"; getch(); start:; do{ clrscr(); cout<<"\n\n\n\n\t\t\t\t/-----------------------\\" <<"\n\t\t\t { Slam Menu... |" |" |" ]\n\t\t\t\t\t"; }" <<"\n\t\t\t\t\\-----------------------/\n" <<"\n\t\t\t\t| 1.| Fill my slam! <<"\n\n\t\t\t\t| 3.| See my slams <<"\n\n\t\t\t\t| 4.| Bid good bye! <<"\n\t\t\t\t/----------------------\\" <<"\n\t\t\t\t[ cin>>op; if(op =='1' ) slamin(); else if(op == '2') modify(); else if(op == '3') show(); else if(op == '4') adios(); else {cout<<"\n\t\tWrong choice chap!! <<"\n\t\t\tPlease see the options carefully and try again." ; getch(); goto start; } }while(1); exit(0); } SELECT A NUMBER <<"\n\n\t\t\t\t| 2.| Modify your slam |"

void slamin() { clrscr(); ofstream fo("slam.dat",ios::app); // file opened in append mode to protect previous data cout<<"\n\n\n\tWhat's your name? "; gets(s1.name); gets(s1.nick); clrscr(); clrscr(); cout<<"\n\n\n\tWhat do your friends call you? "; cout<<"\n\n\n\tWhen were you born ? (dd mm yyyy) "; cin>>s1.dob.d>>s1.dob.m>>s1.dob.y; clrscr(); cout<<"\n\n\n\tWhat's your zodiac sign? "; gets(s1.zodiac); gets(s1.hobbies); clrscr(); clrscr(); cout<<"\n\n\n\tAny hobbies ? "; cout<<"\n\n\n\tYour mobile no. please... "; gets(s1.number); clrscr(); cout<<"\n\n\n\tPostal address.. "; gets(s1.addr); gets(s1.email); gets(s1.quals); gets(s1.l4u); clrscr(); cout<<"\n\n\n\n\tPlease enter a four character code { **** }.\n\t" <<" This will allow you to modify \n" <<"your slam later "; gets(s1.code); clrscr(); clrscr(); clrscr(); cout<<"\n\n\n\tEmail address... "; cout<<"\n\n\n\tWhich qualities do you like in me ? "; cout<<"\n\n\n\tSome lines for me please!\n";

cout<<"\tPress to continue ";getch(); fo.write((char*)&s1,sizeof(s1)); cout<<"\n\n\n\n\t\t\t\t " <<":-)" <<"\n\t\t Slam added !!!\n\nPress any key to continue...::|" ; getche(); fo.close(); } void modify() { clrscr(); char found = 'n',name[26],cd[5]; long pos; fstream fi("slam.dat",ios::in); cout<<"\n\tYour name "; gets(name); cout<<"\n\n\t\t\tYour code please"; gets(cd); while(!fi.eof()) { pos = fi.tellg(); fi.read((char*)&s1,sizeof(s1)); if((strcmp(s1.code,cd)== 0) &&(strcmpi(name,s1.name)==0)) { found = 'y'; clrscr(); cout<<"Name "<<s1.name<<"\nnick name "<<s1.nick <<"\n\nI was born on "<<s1.dob.d<<" "<<s1.dob.m<<" "<<s1.dob.y <<"\t\tMy Star Sign is "<<s1.zodiac <<"\n\n\t I like "<<s1.hobbies<<"\n\n\t Ring me at "<<s1.number <<"\n\nI live at "<<s1.addr<<"\n\n Mail me at "<<s1.email <<"\n\n Things I like about you..\n "<<s1.quals <<"\n\n ... \""<<s1.l4u<<"\"\nLines"<<s1.code; cout<<"\n\n\tEnter the new details...\n"; slam save;

cout<<"\n\tName? (Enter '.'to retain old one)"; gets(save.name); gets(save.nick); clrscr(); clrscr(); clrscr(); cout<<"\n\tWhat do your friends call you? (Enter '.'to retain old one)"; cout<<"\n\tWhen were you born ? (Enter '0 0 0'to retain old one)"; cin>>save.dob.d>>save.dob.m>>save.dob.y; gets(save.zodiac); gets(save.hobbies); gets(save.number); gets(save.addr); gets(save.email); gets(save.quals); clrscr(); clrscr(); clrscr(); clrscr(); clrscr(); clrscr(); cout<<"\n\tEnter your zodiac sign: (Enter '.'to retain old one)"; cout<<"\n\tAny hobbies ? (Enter '.'to retain old one)"; cout<<"\n\tYour mobile no. please... (Enter '.'to retain old one)"; cout<<"\n\tPostal address.. (Enter '.'to retain old one)"; cout<<"\n\tEmail address... (Enter '.'to retain old one)"; cout<<"\n\tWhich qualities do you like in me ? (Enter '.'to retain old one)"; cout<<"\n\tSome lines for me please!(Enter '.'to retain old one)\n"; gets(save.l4u); clrscr(); cout<<"\n\n\n\nPlease enter a four number-code (****)." <<" This will allow you to modify \n" <<"your slam later (Enter '.'to retain old one)"; cin>>save.code; if(strcmp(".",save.name)!= 0) strcpy(s1.name,save.name); if(strcmp(".",save.nick)!= 0) strcpy(s1.nick,save.nick); if(strcmp(".",save.zodiac)!= 0) strcpy(s1.zodiac,save.zodiac); if(strcmp(".",save.hobbies)!= 0)

strcpy(s1.hobbies,save.hobbies); if(strcmp(".",save.number)!= 0) strcpy(s1.number,save.number); if(strcmp(".",save.addr)!= 0) strcpy(s1.addr,save.addr); if(strcmp(".",save.email)!= 0) strcpy(s1.email,save.email); if(strcmp(save.quals,".")!= 0) strcpy(s1.quals,save.quals); if(strcmp(save.l4u,".")!= 0) strcpy(s1.l4u,save.l4u); if(strcmp(save.code,".")!= 0) strcpy(s1.code,save.code); if(save.dob.d!= 0) {s1.dob.d = save.dob.d;s1.dob.m = save.dob.m;s1.dob.y = save.dob.y; } fi.seekp(pos); fi.write((char*)&save,sizeof(save)); break;} } if(found == 'n') {cout<<"Code not found!!"; getch();} fi.close(); } void show() { clrscr(); cout<<"\n-------------------------------------------------------------------------------" <<"|#\t\t\t\tPunit's Slam Book #|"

10

<<"-------------------------------------------------------------------------------"; ifstream fi("slam.dat",ios::in) ; while(fi.read((char*)&s1,sizeof(s1))) {cout<<"\n"<<s1.name<<" "<<s1.nick <<"\n\nI was born on "<<s1.dob.d<<" "<<s1.dob.m<<" "<<s1.dob.y<<"\t\tMy Star Sign is "<<s1.zodiac <<"\n\n\t I like "<<s1.hobbies<<"\n\n\t Ring me at "<<s1.number <<"\n\nI live at "<<s1.addr <<"\n\n Things I like about you..\n "<<s1.quals <<"\n\n \"... "<<s1.l4u<<" ...\"" <<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~$$$$$$$$$$$$$$$$$$$$$$$$~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~"; cout<<"Press a key to see next slam -->\n";getch(); } clrscr(); cout<<"\n\n\n\n\t No more slams !...\n\t\t Press any key to return \n\n\n\n\t\t\t\t\t<--"; getch(); } void adios() { clrscr(); char ch; cout<<"\n\n\n\n\t\t\t <<"\n\t\t\t ///////////////////////////////////////////" //// /////" " " ///// // //\n\t\t\t\t " ; ( "<<s1.email<<" )\n\nFriends call me

<<"\n\t\t\t //// Really wanna quit ? .. (y / n) ///// <<"\n\t\t\t //// <<"\n\t\t\t <<"\n\t\t\t///////////////////////////////////////////"

11

cin>>ch; if(ch=='y'||ch=='Y') exit(0); }

SCREEN SHOTS

FOUR|4

12

13

14

REFERENCES

ONE|1

o Computer Science with C++ by Sumita Arora o Guide of Reference to C++ by Tata-McGraw Hill
LINKS TWO|2

o www.cs76.net o www.github.google.com
o

www.thinkdigit.com

15

You might also like