Sei sulla pagina 1di 46

COMPUTER

A Computer is an electronic device that can perform a variety of operations in accordance with a set of instructions called programs. They can access & process data millions of times faster than humans can .A computer can store data & information in its memory, process them & produce the desired results. Computers can do a lot of different tasks such as playing games, railway reservations, weather forecasting, error detection & controlling as a data processor.

DATA: Data in a computer technology means raw facts & figures. Data are processed to form information. INFORMATION: It means meaningful data. Data are aggregated & summarized in various meaningful ways to form information.

FUNCTIONAL COMPONENTS OF A COMPUTER


INPUT UNIT CPU MAIN MEMORY OUTPUT UNIT

INTRODUCTION
To perform the manipulative miracles, programs need tools for performing repetitive actions & for making decisions. C++ providing

statements to attain so. Such statements are called program control statements.

STATEMENTS
These are the instructions given to the computer to perform any kind of action, be it data movements, be it making decisions or be it repeating actions. Statements from the smallest executable unit within a C++ program. Statements are terminated with asemicolon (;). The simplest statement is the empty or null statement. It takes the following form: // it is a null statement; NULL STATEMENT is useful in those instances where the syntax of the language requires the presence of a statement but where the logic of the program does not. We will see it in loops & their bodies.

SEQUENCE
The sequence construct means the statements are being executed sequentially. This represents the default flow of statement.Every program of C++ begins with the first statement of ().

SELECTION
The selection construct means the execution of statements depending upon a condition test. If a condition evaluation to true, a course of action is followed. This construct is also called decision construct because it helps in making decision about which set of statement is to be executed.

ITERATION
The iteration construct means repetition of a set of statements depending upon a condition test .Till the time a condition is true (or false depending upon the loop),a set of statement is repeated again & again. As soon as the condition becomes false (or true), the repetition stops. The iteration construct is also called looping construct. Condition ? True Statement 1 Statement false The exit condition The loop body

SELECTION STATEMENT
The selection statement allows to choose the set of instructions for execution depending upon an expression s truth value. C++ provides two type of selection statements: y If

y Switch In addition, in certain circumstances operator can be used as an alternative to if statement. The selection statement are also called conditional statements or decision statements. y The If statement of C++ An if statement tests a particular condition; if the condition evaluates to true, a course of action is followed i.e. a statement or a set of statements is executed. Otherwise, the course of action is ignored. The syntax of the if statement is : If (expression) Statement; y The switch statement of C++ It is a multiple-branch selection statement. This selection statement successively tests the value of an expression against a list of integers or characters constants. When a match is found, the statements associated with that constant are executed. The syntax of switch statement is as follows: Switch(expression) Case constant n-l: statement sequence n-l; Break; {default statement sequence n]; } This expression is evaluated and its values are matched against the values of the constants specified in the case statements. When a match is found, the statement sequence associated with that case is executed until the break statement or the end of switch statement is reached. The default statement gets

executed when no match is found. The default statement is optional and if it is missing, no action takes place if all match is fail. The ANSI standards specifies that a switch can have upto 257 case statements. When a break statement is encountered in a switch statement, program execution jumps to the lines of code following the switch statement, that is outside the body of switch statement.

Iteration statements
The iteration statements allow a set of instruction to be performed repeatedly until a certain condition is fulfilled. The iteration statements are also called loops or looping statements. C++ provides three kinds of looping statements: y For loop y While loop y Do-while loop Test Expression True { Body Of The Loop} Update expression(s) The execution of a for loop y The while loop

false exit

It is an entry controlled loop. The syntax of the while loop is: While (expression) Loop body; Where the loop body may contain a single statement, a compound statement or an empty statement. The loop iterates while the expression evaluates to truth. When the expression becomes false, the program control passes to the line after the loop body code. In a while loop, a loop control variables should be initialized before the loop begins as an uninitialized variable can be used in an expression. The loop variable should be updated inside the body of the while. y The do-while loop The do-while is an exit-controlled loop,that is it evaluates its test expression at the bottom of the loop after executing its loop body statements. This means that it always execute at least once. The syntax of do-while loop is: DO { Statement; } y The nested loop A loop may contain another loop in its body. In a nested loop, the inner loop must terminate before the outer loops. The following is an example of a nested loop: For (i+1;i<5;++i) { if outer loop Cout<< \n ;

For (l=j;+I;++j)

CLASSES
A class is a way to bind the data describing an entity and its associated functions together. In C++ I class makes a data type that is to create object of this type . classes are needed to represent real world entities that not only have data type properties but also their associated operations. Class account { int account no; Char type; float balance; Float deposit (float amt) { balance + = amt; Return balance;

DECLARATION OF CLASSES
The declaration of classes involves declaration of its four associated Attributes: 1. DATA MEMBERS: These are the data type properties that describe the characteristics of class. 2. MEMBER FUNCTION: These are the set of operations that may be applied to objects of that class. 3. PROGRAM ACCESS LEVELS: These control access to members from within the program. These access levels are private, protected or public. 4. CASH TAG NAME: These serve as a type of specified for the class using which objects of this class type can be created. The class specification takes place in two parts:

y CLASS DEFINITION: This describes the component members of a class. The general form of a class definition is as given below: Class class -name { Private: Variable declaration; Function declaration; Public: Variable declaration; Function declaration; }; y Class method definitions: this describes the use of how certain class member function are implemented. Member functions can b defined in two parts: y Outside the class definition: the general form of a member function definition is: { Function body } ( where the class name indicates that the function is specified by class name . The symbol called the scope resolution operator(::),specifies that the scope of the function is restricted to the class name .) y Inside the class definition: In this , there is no need to put membership label along with the function name. functions defined in a class specification are: There are two ways in which a class definition can be laid-out.

1. The first way is to place the private data before public functions and data.foe eg , Class sample { Int a ; Double b; Public ;void add(); Void print(); }; 2. The second way is to place the public member first, followed by protected and private members. For eg .., Class sample { Public: //data members .. //function members : : : };

REFERENCING CLASS MEMBERS


A class specification does not define any objects of its type; rather it just defines the proprieties of class. The members of a class are referenced using object of a class. For instances consider the following class: Class ABC {int x, y; /private by deafault Public: Int z;

Int add (int a,int b) {int c=a+b; Return c; } Int sub(int a, int b) { Int c=a-b; Return c; } }; The private data of a class can be accessed only through the member function of that class. The public data can be accessed by non-member functions through the objects of that class. The public member functions of a class are called by non-member functions using the objects. The general format for calling member function is: Object-name function-name (actual arguments); Calling a member function of an object is known as sending message to the object. Similarly, to access public data member, the format used is: Object-name, public data members

USING OBJECTS
When a class is defined, it does not define or create objects of that class, rather it only specifies what type of information the objects of this class type will be containing. Once a class has been defined, its objects can be created like any other variable, using the class name as type specifies as it is shown below: Class-name object list (comma separated):

For instance, consider the following code fragments: Class its {public Int intemno; Float price; Void getdata(int l,intj) { Intemno=l; Price=j; } Void putdata (void) { cout<< items <<intemno; Cout<< \n << price: << \n ; } }; Items s1, s2 Int main () { s1. Getdata(100,17.50); S2. Getdata (1002, 29.00); : : : : } In the above code fragment, after defining the class item, the Statement Items s1,s2; Creates two objects s1 & s2 of type items in the memory.

When you call a member function, it uses the data member of the particular object used to invoke the member function.

SCOPE OF CLASS AND ITS MEMBERS


A class in C++ represents a group of data & associated functions divided into one or more of these parts: public, private & protected. 1. Public members are the members ( data members & members functions) yhat can be used by any function, i.e. the keyboard public identifies class members that constitute the public interface for the class. 2. Private members are the class members that are hidden from the outside world. The private members of a class can be used only by member functions (and friend functions) of the class in which it is declared. 3. Protected members are the members that can be used only by member functions & friends of the class in which it is declared. The difference between protected & private members is that the former are inheritable while the latter are non inheritable.

FRIEND FUNCTIONS
A friend function is a member function that s granted access to a class s private & protected members. A friend class is a class whose member functions can access another class private & protected members. To declare a non-member functions as a friend of a class, its prototype declaration starting with the keyword friend should be included in the class definition. For instance, to make an

outside function check() as a friend to the class sample, the class definition may look like: Class sample (private: : Public: : Friend void check (void); //declaration Included };

INCLINE FUNCTIONS
The incline functions are a C++ enhancements designed to speed up programming. The coding of normal functions & inline functions are similar excepted that inline functions definition starts with the keyword inline.

MEMORY ALLOCATION OF OBJECTS


The memory space for objects is allocated when they are declared & not when the class is defined that i.e member functions are created & placed in the memory space only once when the class is defined, the memory space is allocated for objects data members only when the objects are declared. No separate space is allocated for member function when the objects are created. Since all the objects belonging to a class use the same member functions, there is no print allocating separate space for each object. Thus, member functions are created & stored when the class is defined & this memory space can be read by any of the objects of that class.

Separate space is allocate to objects at the time of their declaration for their data members only, because the data members hold different values for different objects.

INHERITANCE: EXTENDING CLASSES


Inheritance is capability of one class of to inherit properties from another class. The class inheritance lets you derive new classes (called derived classes) from old ones, with the derived class inheriting the properties, including the methods of the old class, known as base class.

DIFFERENT FORMS OF INHERITANCE


As you have read that new class can be derived from an existing class. Then the new derived class is called derived class or sub class and the existing class is called base class or super class. Inheritance may take place in many forms: 1. Single Inheritance: When a subclasses inherits only from one base class, it is known as single inheritance. 2. Multiple Inheritance: When a subclass inherits from multiple base classes, it is known as multiple inheritance. 3. Hierarchal Inheritance: When many sub classes inherit from a single base class, it is known as hierarchical inheritance. 4. Multilevel Inheritance: The transitive nature of inheritance is reflected by this form of inheritance. When a subclass inherits from a class that itself inherits from another class, it is known as multilevel inheritance. 5. Hybrid Inheritance: Hybrid inheritance combines two or more form of inheritance e.g, when a sub class inherits from

multiple base classes and all of its base classes inherits from a single base class, this form of inheritance is known as hybrid inheritance.

DERIVED AND BASE CLASSES


1. Single Inheritance: Class derived-class-name : visibility-mode- base-class name { : //members of derived class }; Examples of derived class definitions:

Class sub: public Super //public derivation { : //members of sub(the derived class }; Class Sub: private Super //private derivation //members of sub }; Class sub: protected Super //protected derivation { //members of sub }; Class Sub: Super //private derivation by default { : };

2. Multiple Inheritance Class derived_class_name : vis_mode base 1, vis_mode Base2 [vis_mode base3 .] { //members of derived class }; Where vis_mode is the visibility mode and base1, base2, base3, etc. are names of multiple base classes. For instances Class Sub: public Super A, private B { //members };

INHERITANCE AND CONSTRUCTORS AND DESTRUCTORS


For instances , in the following code fragment Class super { :

}; Class Sub : public Super { }; Int main() { sub ob1; : } The constructor of the base class uses a special argument. Derived :: Derived (type1 x, type2 y ..): Base (x,y) { : : }

INTRODUCTION TO PROJECT CALENDAR


CALENDARS are normally based on astronomical events & the two most important astronomical objects are the sun and the moon. Their cycles are very important in the constructions & understanding of calendars.

A calendar is a system of organizing units of time for the purpose of reckoning time over extended period. By convention, the day is the smallest calendar unit of time. The measurement of fractions of a day Is classified as timekeeping. The general definition of calendar is due to the diversity of methods that have been used in creating calendars. Although some calendars replicate astronomical cycles according to fixed rules, other are based on abstractly, perpetually repeating cycles of no astronomical significance. Some redundantly enumerate every units, & some contains ambiguities. Some calendars are codified in written laws; others are transmitted by oral traditions.

The common theme of calendar making is the desires to organize units of time of satisfy the needs & preoccupations of society, in addition to serving practical purposes, process of organization provides a sense. However, a link between mankind & the cosmos, it is little wonder that calendars have held a sacred status & have served as a source of social order & cultural identity. Calendars have provided the basis for planning agricultural, hunting & migration cycles for divination & Prognostication & for maintaining cycles. Of religious & civil events.

Whatever their scientific sophistication, calendars must ultimately be judged as social contracts, not as scientific treaties. Our concept of a year is based on the earth s motion around the sun. Concept of moon is based on the moon s motion around the earth, although the connection has been broken in the calendar commonly used now. The calendar used throughout the word is Gregorian calendar also called Christian calendar . MONTH
January February March April

LATIN
Januaries Februaries Marti us Aprillis

ORIGIN
Named after God Janus Named after februa, the purification festival. Named after the God Mars Named after the Goddess Aphrodite or the latin word Aperire, to open Probably named after Goddess maia Probably named after the goddess juno named after Julius Caesar in 44 b.c. From the word septem, seven, because it was the 7th month in the old roman calendar. From the word octo, eight -8th month in the old roman calendar. From the word novem, nine-9th month old roman calendar.

May June July September

Maius Junius Julius September

October

October

November

November

December

December

From the word decem, ten-10th month of old roman calendar.

The Christian calendar is based on the motion of the earth around the sun, while the months have no connection with the motion of the moon. The Islamic calendar is based on the motion of the moon, while the year has no connection with the motion of the earth around the sun. The jewish calendar combines both, i.e. years are linked to the motion of the earth around the sun, & its months are linked to the motion of the moon. The following algorithm for computing the data of Easter is based on the algorithm of Odin (1940). It is valid for any Gregorian year, Y. all variables are integers & the remainders of all divisions are dropped. The final data is given by M the month & D the day of the month.

INTRODUCTION TO C++
The C++ programming language was developed at AT&T Bell laboratories in the early 1980s by Bjarne stroustroup. He extended the C language by adding features from Simula 67. Simula 67 was one of the earliest object oriented languages. Bjarne stroustroup called it C with classes. The name C++ was coined by Rick Mascitti where ++ is the increment operator. The maturation of the C++ language attested to by two events:

1. The formation of an ANSI (American National Standard Institute) C++ Committee. 2. The publication of the Annotated C++ Reference Manual by Ellis and Stroustroup.

C++

CHARACTERSET

Character set is a set of valid characters that a language can recognize. A character represents any letter digit or any other sign. The C++ has the following character set: Letter: A Z, a-z Digits: 0-9 Special symbols: space +-*/(){}[]= / ?>.<,=\|!@#$%^&* underscore etc. White spaces: Blank spaces, Horizontal tab( ) Carriage Return New line , form feed. Other characters: C++ can process any of the 256 ASCII characters as the data or as literals.

HARDWARE SPECIFICATIONS
1. 2. 3. 4. PENTIUM III 866HZ 1.44 Mega Bytes Floppy disk drive 40 Giga bytes Hard disk drive 128 Mega bytes Random Access Memory

5. 52x compact disk Read only Memory 6. Colored Monitor 7. Inkjet printer

SOFTWARE SPECIFICATIONS
1. DOS Version 4.90.300 2. Turbo C++ Version 3.0

OBJECT
An object is an identification entity with some characteristics & behavior.

PROCEDURAL PROGRAMMING
A program in a procedural language is a list of instructions where each statements tells the computer to do something. The focus is on the processing, the algorithm needed to perform the desired computations. The paradigm is: Decide which procedures you want; use the best algorithm you can find.

OBJECT ORIENTED PROGRAMMING


Object oriented programming is based on the principles of data hiding, abstraction, encapsulation, modularity, inheritance, & polymorphism. It implements program using the objects in an objects oriented language. In OOP programming object

represents an entity that can store data & has its interface through functions.

INTRODUCTION TO FILE
A file is a named collection of logically related information. Day by day, with the rapidly growing information technology. The computers are becoming more and more capable and able to perform complex functions with bulk of data. This bulk of data is stored in files. There are at least three good reasons. These are as follows:
1. Any data or instructions, which are to processed upon, are to be present in the main memory, after the processing ends, the operating system reallocates the space occupied by processed data/instructions to another program the date /instructions of the first program are gone. By contrast, if this data/instructions is stored in a file on secondary storage, it provides permanent data storage. Even after the data/instructions are lost from the main memory, these are available on the secondary storage for later use. 2. Files can also store a data collection, which is too large to fit the available main memory. 3. Also, if a program requires only a small portion of data, then rest of the data resides on files, securing data for later use. Therefore, a file is an important factor of information management of computer system.

COMPENENTS OF A FILE
BYTE: a byte is a group of eight bits & is used to store a character. Data item (field): a data item is the smallest unit of named data. It may consist of any number of bits or bytes. A data item represents one type of information & is often referred to as field or data element. Data aggregate (group item): a data aggregate (also called group item) is a named collection of data items within a record & is referred to as a whole.
For example, a data aggregated called DATE may be composed of data item Month, DAY & YEAR. Record: a record is a named collection of data items, which represents a complete unit of information.

FILE ORGANISATION
It greatly affects the basic operation performed on files. These basic operations are performed in different manners for every file organization. The fundamental operations that are performed on the files are as follows: 1. Creation 2. Updation y Insertion y Modification y Deletion 3. Retrieval y Query

y Report generation 4. Maintenance y Restructuring y Reorganization

CREATING OF A FILE
This process involves data collection validation & making record structures. A record structure is determined by deciding its field & field lengths. First of all space is allocated for the file on the secondary storage medium & then, collection data are stored in it.

UPDATION OF A FILE
Changing the contents of a file to make it reflect the latest data. Data/ information is known as Updation of a file. The process of Updation involves, 1. Insertion: Addition of a record if anew data/information is to be added in the field. E.g if a new employee joins an organization, his/her record will be inserted in the file. 2. Modification: In it an existing record if a part of it charge, e.g if an employee changes has been promoted & transferred (his designation & department have changed), this changed information is to be stored in the record by performing modification. 3.Deletion: of a record if it is not required any more, e.g. if an employee leaves or retires, his record is not needed any more, therefore, his record will be deleted from the file.

RETRIEVAL FROM A FILE

Extracting meaningful information by reading a file is called retrieval. It can be of two types: y Query: means inquiry by a user, when a user wants to have some information , he/she queries upon the files. y Report generation: means generation of a report ..(large data)

MAINTENANCE OF A FILE
Maintenance of a file means making changes in order to improve its very performance. There are two basic classes of file maintenance operations: y Restructuring: it means changing the structure of a file (which involves its record structure, record length etc.)without affecting the file organization, e.g. changing field widths, adding or removing fields to records etc. y Reorganization: it means changing the file organization itself. This involves restructuring the file once again for the new file organization. File maintenance also involves storing different versions of file (i.e. same flies with same changes called dump files) for future use. Therefore, maintenance & Updation is done in the same run with Updation, new version of the file is created & previous one is kept for the purpose of file maintenance.

FILE CONCEPTS
A STREAM is a sequence of bytes FUNCTIONS OF FILE STREAM CLASSES;

1. Filebuf: It sets the file buffers to read and write. It contains close( ) and open ( ) member functions in it. 2. Fstreambase: This is the base class for fstream, ifstream and of stream classes. therefore , it provides operation common to these file streams. It also contains open() and close () function. 3. Ifstream: Being an input file stream class, it provides input operations for file, it inherits the functions get (), getline (), read () and functions supporting random access seeking () and telig() from ostream class defined inside iostream.h file. 4. Ofstream: Being an output file stream class, it provides output operations. It inherits put () and write () functions along with functions supporting random access sekup () amd tekko () from ostream class defined inside iostream.h file. 5. Fstream: It is an input-output file stream class. It provides support for simultaneous input and output operations. It inherits all the functions from stream and ostream classes through iostream class defined inside iostream.h file. OPENING AND CLOSING FILES In C++, with a file we must first obtain a stream. A stream is a sequence of bytes. There are three types of streams; input, output and in put/out. To create an input stream, we must declare the stream to be of class ifstream. To create an output stream, we must declare the stream to be of class fstream. Once a stream has been created next step is to associate a file with it. And after the file is available for processing. Opening of files can be achieved in two ways:

i.

Using the constructor function of the stream class: The constructors of stream classes (ifstream, of stream, or fstream) are used to initialize file stream objects with the filenames passed to them. This is carried out as shown below: To open a file, datafile , as an input file (i.e data will be read from it and no other operation like writing or modifying would take place on the file), we shall create a file stream object of input type i.e, ifstream type: Ifstream input file(Datafile ), ii) Using the function open () The first method is preferred when a single file is used with a strem. However, for managing multiple files with the same strem, the second method is preferred. If the situation demands sequential processing of files (Le. Processing them one by one ), then you can open a single stream and associate it with each file in turn. To use this approach, declare a stream object without initializing it, then use a second statement to associate the streams with a file. For instance. Ifstream filin ; / create an input stream Filin.open ( Master.dat ); / associate filin stream with the Master.

CLOSING A FILE A file is closed by disconnecting it with the stream it with the stream it is associated with. The Close () function accomplishes this task and it takes the following general form: Stream-object.close (); For instance, if a file master is connected with an of stream object fout, its connwction with the stream fout can be terminate by the following statement: Fout.close ();  Start  Include header file  Connect calendar file to output stream-fout  Declaration of global variable  Seclaration of global class-Calandar  Define global class Calendar 1  Declare integer variable and member function under public spectrum of class Calendar 1  Derive class Calendar 2 from class Calendar 1  Define class Calendar 2 and declare member functions under public section of class calendar 2  Define member function outside the class definition. Declare object of class Calendar 2 inside main  Display menu  Ask the user to enter choice. If choice entered is 1, then ask for year, month and date of which he wants to see the corresponding day.  Display the day corresponding to the entered date

 If the choice entered is 2, then ask for your year and month of which he wants to see the corresponding calendar. Display calendar for the entered month  If the choice entered is 3, then ask for year and month, starting from which he wants to see the calendar of the entered year  Display the calendar for all the remaining months starting from the entered month  If choice entered is other than 1,2 or 3 display error message  Stop

PROGRAM
/* A program that prints date corresponding to date, month & year entered by the user. Month calendar based on the month & year entered by the user. YEAR CALENDAR BASED ON THE MONTH AND YEAR ENTERED BY THE USER. */ //files to be included in the program are#include<iostream.h> #include<conio.h> #include<fstream.h> #include<dos.h> #include<process.h>

//for clrscr( ) & getch ( ) functions //to input & output facilities //for delay function //for exit( ) function

//global declaration of variables Int month_days[]={31,28,31,30,31,30,31,31,30,31,30,31}; Int byr=1980; Int count, cony,j,f,l,h,k; //global pointer variable declaration Char *month_names[]={ January , Feburary , March , April , May , june , August , September , October , November , December }; Char *week_days[]={ sun , mon , tue , wed , thur , fri , sat }; Class calendar 1 //class definition

{ Public: Int month,year,day,date Int isleap (int v) { If (v%4==0) Return 1; Else Return 0; } Int dif (int v) { If (v%4==0) Return 29; Else Return 28; } };

//data members // member function definition

//member function definition

Class calendar2:public calendar1 //derived class defined { Public: Int diy (int); Int dim (int,int); Void check_leap (int year) //member function {

If (year%4==0) Month_days[1]=29; Else Month_days[1]=28; } }; Int calendar2::diy(int v) { Int v1=0; For (int n=byr, n<v;++n) { If (isleap(n)==1) V1=v1+366; Else V1=v1+365; } Return v1; } Int calendar2::dim(int v, int y) { Int v1; If (v==1) V1=0; Else if (v==2) V1=31; Else if (v==3) V1=31+dif(y);

//memberfunction definition //of class derived class //calendar2

Else if (v==4) V1=dif(y)+62; Else if (v==5) V1=dif(y)+92; Else if (v==6) V1=dif(y)+123; Else if (v==7) V1=dif(y)+153; Else if (v==8) V1=dif(y)+184; Else if (v==9) V1=dif(y)+215; Else if (v==10) V1=dif(y)+245; Else if (v==11) V1=dif(y)+276; Else if (v==12) V1=dif(y)+306; Return v1; } Void main () { Clrscr(); Int ch; Calendar2 ob;

//function call fo dif ( )

//main ( ) body begins

//object of class calendar2 declared

Cout<< \n PROGAM THAT PERFORMS THE VARIOUS FUNCTIONS TO SHOW CALENDAR FOR ; Cout<< \n FOR A PARTICULAR DA, MONTH, AND YEAR\n\n\n ; Cout<<\n\t\t MAIN MENU \n\t\t ; Cout<< 1.day corresponding to a particular date \n\t\t ; Cout<< 2.calendar for a particular month \n\t\t ; Cout<< 3.calendar for the whole year \n\t\t ; Cout<< 4.exit \n\n ; Cout<< enter the choice(1-4) ; Cin>>ch; Clrscr( ); Switch(ch) { Case 1: //switch body begins Ofstream fout; //connecting file calendar to output stream fout Fout.open ( calendar ); Int yd,md,td; //temporary variables declared for use in Calculation Cout << enter the value of the year (eg 2001) or 0 to quit the program: ; Cout<< enter the value of the year (eg 2001) or 0to quit the program: ; Cin>>ob.year; //accessing data member with object Clrscr; If (ob.year<0) {

Cout<< invalid input!!!!!!!!!!! ; Cout<< invalid input!!!!!!!!!!! ; Cout<< year should start from 1 n ; Cout<< year should start from 1 n ; Cout<< TRY AGAIN!!!!!!! ; fout<< TRY AGAIN!!!!!!! ; Delay (3000); Main( ); //function call for main } If (ob.year==0) { Exit (0); }

//to come out of loop

Cout<< enter a month(1-12): ; Cout<< enter a month(1-12): ; Cin>>ob.month; Clrscr( ); If (ob.month>12||ob.month<0) { Cout<< INVALID INPUT!!! ; fout<< INVALID INPUT!!! ; cout<< month value should be between 1-12 ; fout<< month value should be between 1-12 ; cout<< TRY AGAIN ; cout<< TRY AGAIN ;

delay (3000); main ( ); //function call for main } Cout<< enter date: ; Cout<< enter date: ; Cin>>ob.date; Clrscr( ); //calculate day Ob.check_leap(ob.year); //member function called Yd=ob.diy(ob.year); //member function called Md=ob.dim(ob.month,ob.year); //member function called Td=yd+md+pb.date; Ob.day=(td%7)+1; Clrscr; //screen format for a day calendar Cout<< year: ob.year; Cout<< \nmonth: <<month_names[ob.month-1]; Cout<< \n date: <<ob.date; Cout<< \n corresponding day is: ; Cout<<\n corresponding day is:; Switch (ob.day) //switch ( ) body begins { Case 1: cout<< Monday ;

Break; Case 2: cout<< Tuesday ; Break; Case 3: cout<< Wednesday ; Break; Case 4: cout<< Thursday ; Break; Case 5: cout<< Friday ; Break; Case 6: cout<< Saturday ; Break; Case 7: cout<< Sunday ; Break; } //switch body ends Cout<< \n\n HIT ENTER to continue or ESCAPE to quite .. ; fout<< \n\n HIT ENTER to continue or ESCAPE to quite . ; char cont=getch ( ); j=f=h=k=0; if (cont==13) //ASCII VALUE FOR ENTER IS 13 main( ); else if (cont==27) //ASCII VALUE FOR ESCAPE IS 27 { Exit (0); } Fout.close ( ); Break; //disconnecting file calendar from output stream fout

Case 2 : Ifstream fin; Fin.open ( calendar );

//connecting file calendar to input

Cout<< enter the value of year (eg 2001) or 0 to quit program: ; Cin>>ob.year; Fin>>ob.year; Clrscr( ); If (ob.year<0) { Cout<< invalid input ; Cout<< year should start from 1 .n ; Cout<< TRY AGAIN!!! ; Delay (3000); Main( ); //function call for main } If (ob.year==0) { Exit (0); } Cout<< enter a month (1-12) ; Cin>>ob.month; Fin>>ob.month; Clrscr(); If (ob.month>12||ob.month<0)

{ Cout<< INVALID INPUT!!!! Cout<< month should be between 1 to 12 ; Cout<< TRY AGAIN!!!! ; Delay (3000); Main( ); } //check for a year if it is a leap Ob.check_leap (ob.year); Ob.check_leap (ob.year); //member function called Yd=ob.diy(ob.year); //member function called Md=ob.dim(ob.month,ob.year); //member function called Td=yd+md+ob.date; Ob.day=(td%7)+1; Clrscr(); Cout<< year: <<ob.year; Cout<< /n month: <<month_names[ob.month-1]; Cout<< \n sun\t mon\ttue \twed\tthu\tfri\tsat\n ; Count=ob.day; For (i=1;i<=month_days[ob.month-1];++1) { Cout<<i<< \t ; If (cout==7) { cout<< \n ;

Count=0; } Count++; } Cout<< \n\n HIT ENTER to continue or ESCAPE to QUIT ; Cont=getch( ); If (cont==13) Main( ); Else if (cont==27) { Exit (0); }fin.close( ); //disconnecting file calendar from input stream fin Break; Case 3: Ob.month=1; Cout<< enter the value of year (eg 2001) or 0 to quit program: ; Cin>ob.year; Clrscr( ); If (ob.year<0) { Cout<< INVALID INPUT!!!!! ; Cout<< year should start from 1 .n ; Cout<< try again!!!! ; Delay (3000); Main( ); //function call for main( )

} If (ob.year==0) { Exit (0); } //check for a year if it is a leap Ob.check_leap(ob.year); //calculate days Do { Ob.check_leap(ob.year); //member function called Yd=ob.diy(ob.year); Md=ob.dim(ob.month,ob.year); Td=yd+md+ob.date; Ob.day=(td%7); Clrscr(); Ob.day=count; Clrscr(); Cout<< year: <<ob.year; Cout<< \nmonth: <<month_names[ob.month-1]; Cout<< \nsun\nmon\ntue\nwed\nthu\nfri\nsat\n ; Count=ob.day; //screen formate for your calendar For(i=1;i<=month_days[ob.month-1];++i) { Cout<<i<< \t ; If(count==7)

{ Count=1; } Count ++; } Cout<< \n\nstrike any key to view next ; Cont=getch(); Clrscr(); For (i=1;i<month_days[ob.month-1];++i) { Ob.day++; If(ob.day==7) Ob.day=1; } ob.month++; } While(ob.month!=13); Cout<< HIT ENTER to CONTINUE or ESCAPE TO QUIT .. ; Cont=getch(); J=f=i=h=k=0; If (int(cont)==13) Main(); Else if(int(cont)==27) Exit(0); Break; Case4: Exit(0); Default:

Cout<< wrong choice!!! ; Cout<< your choice should be between 1 and 4 ; Cout<< TRY AGAIN!!! ; delay(3000); main(); break; } //switch body ends Getch(); //waiting function } //main() body ends

Potrebbero piacerti anche