Thursday 14 February 2013

The exit() Functions in C Programming Language



In case of any file input-output error or erroneous command line arguments, it is possible to terminate program execution. This can be done through the exit() function as shown in the following example:

if( argc!= 3)
{
printf("Invalid arguments\n");
exit();
}

An integer may also be passed as a parameter to the exit() function. In UNIX, this value is stored in the environmental variable "$?", and should be in the range 0 - 255.

The stdin, stdout and stderr FILE type Pointers



The stdin, stdout and stderr are names used to refer to the standard input device (keyboard) and standard output and error device (VDU). These are actually FILE type pointers, defined in the file stdio.h, and can be used with file input-output functions.

For example, the following statement:

fputc (c, stdout);

writes the value of the char type variable c onto the VDU.

The standard input, output and error files are not opened within C programs, since the operating system makes these devices available for all programs.

The NULL Return Value in C Language



In case fopen() is unsuccessfull in opening a file, it send s back a null(zero) value called NULL. NULL is defined in the file stdio.h.

For example, the following statement.

if((fp = fopen ("a.dat", "r")) == NULL)

can be used to test whether the file a.dat has been opened successfully or not.

Closing Files in C Programming Language


Closing Files

Each file is closed by one fclose() statement as shown in the following code:

#include<stdio.h>
main()
{
:
:
fclose(ptr1);
fclose(ptr2);
}

The above code is used to close files.

fclose() statement is used to close files.

Reading from and writing to Files in C Language



In C, character input-output functions from files are simple extensions of the corresponding functions for input-ouput from/to the terminal. So, there are funcitons such as:

fgetc()
fputc()

The only additional parameter of both functions is the appropriate file pointer, so that the file to be used for input-output is known.

The following code performs the actual copying of contents of a.dat to b.dat:

#include<stdio.h>
main()
{
char c;
:
:
while((c=fgetc(ptr1))!= EOF)
fputc(c, ptr2);
}

The fgetc() function reads one character at a time from a file, assigns it to a character variable, and moves the file pointer to the next character.

fgetc() actually returns an integer type of value, which is type cast into a character type before being assigned to c.

Opening Files in C Language



The C statements that would do this are:

#include<stdio.h>
main()
{
FILE *ptr1, *ptr2;
ptr1 = fopen ("a.dat", "r");
ptr2 = fopen ("b.dat", "w");
----
----
}

The function fopen() opens a file in the appropriate access mode.

When a file is opened, certain information regarding that file automatically gets stored in different variables. These variables are collectively classified as the data type FILE. fopen() returns a pointer to this FILE type data. Hence, the following declaration is required for defining the two pointers:

FILE *ptr1, *ptr2;

The definition of the data type FILE is provided in a standard header file called stdio.h, which is therefore included in this program.

The parameters r and w in the fopen() statements indicate the mode of access to these files.

C allows a number of modes in which a file can be opened.


File Handling in C Programming Language



The treatment of files in C is very simple, unlike that of other programming languages where there are special in-built and often rigid file structures and file-handling routines. C treats file input-output in much the same way as input-output from/ to the terminal, and provides file input-output functions, very similar to those for input-output from/to the terminal.

The simplicity of the input-output in C lies in the fact that it essentially treats a file as a stream of characters and accordingly allows input-output in streams of characters. Functions are available for single character as well as multiple character input-output from/to files.

This simplicity has the advantage that the programmer can read and write onto a file as he/she wishes to.

This post uses the example of a file-copy program, which copies the contents of a file called a.dat to a file called b.dat to explain file input-output.

The steps involved in copying are:

1. Opening both files, one to read from, the other to write to.

2. Reading one character from the file a.dat, writing it onto b.dat, until the end of a.dat.

3. Closing both files.

sprintf(), sscanf() Functions for Formatting Data in Memory



The formatting functions available as part of the standard library for formatting data in memory, are:

-> sprintf()

->sscanf()

These functions, like printf() or scanf(), write variables to a destination or read data for variables from a destination. The difference is that while printf() writes to the screen, sprintf "writes" to a variable in the memory. Similarly while scanf() reads from the keyboad into variables, sscanf() "read" from a variable in the memory and stores the data in different variables specified. These funcions are used for transferring data between variables in a specific format.

The syntax of the above functions is similar to that of the functions, fprintf() and fscanf() respectively.

The syntax of the functions sprintf() is:

sprintf( string, format-specification, data, ...);

where,

string  - is a pointer to the destination string in memory which will contain the formatted data as per the format specification.

format- specification  - is the specification of how data is to be formatted

The function sprintf() is useful for formatting data and controlling the width of the destination string.

The sytax of the function sscanf() is:

sscanf(string, format-specification, variable, ..);



atoi(), atof() Standard String to Numeric Conversion Functions


atoi()


This function returns the int type value of a string passed to it and the value() in case the string does not begin with a digit.

For example, if the array str1 contains the string "1234", then the following statement:

y = atoi(str1);

will cause y to have the value 1234.

However, if the array str1 contains the string "ABC", then the following statement:

y = atoi(str1);

will cause y to have the value().

atof()


This function returns the double type value of a string passed to it and the value 0 in case the string does not begin with a digit or a decimal point.

For example, if the array str1 contains the string "1234", then the following statement:

y = atof(str1);

will caluse y to have the value 1234.0000.

However, to use atof(), the following declaration must be included in the program:

double atof();

since it returns a non-integer value.

Standard String - Handling Functions in C



A brief description of some of the standard string functions of C given below,

strcmp()

strcmp() compares 2 strings (its parameters) character by character (ASCII comparison) and returns any of the integer values. less than(), greater than().

strcpy()

strcpy() copies the second string to the first string named in the strcpy() parameters.

For example, the following statement:

strcpy (str1, "ABC");

will copy the string "ABC" to the array str1.

strcat()

strcat() appends the second string passed at the end of the first string passed to it.

For example:

strcat (str1, "ABC");

will add the string "ABC" to the contents of the array str1.

strlen()

This function returns the number of characters in the string passed to it. The length does not include the NULL character.

For example, if the array str1 contains the string "1234", then the following statement:

y = strlen(str1);

will cause y to have the value 4.

SURROGAT cLASS in z/OS Mainframe System



A surrogate user can submit jobs on behalf of another user without having to specify the original user's password.
The Original user specified on the job card.

Job submitted by the surrogate users execute with the authority of the original user.

The output of the job owned by the commands.

-> RDEF SURROGAT RAM.SUBMIT UACC(NONE) NOTIFY(RAM).

-> SETR RACLIST(SURROGAT) REFRESH

-> PERMIT RAM SUBMIT CLASS(SURROGAT) ID(OPER001) ACCESS(READ).

How to Delete General Resource Profiles ?



The following command are used to delete the general resource profiles.

-> RDELETE|RDEL cls_name prfl_name.

-> RDEL OPERCMDS MVS.DISPLAY.PDS.

RACLIST

RACLIST is list of frequently accessed profiless maintained in real storage.

How to Protect General Resource Profiles



The RDEFINE Command is used to define the general resource profile to the RACF database.

-> RDEF OPERCMDS MVS.DISPLAY.PDS UACC(NONE) NOTIFY(DFSMS)

-> SETR RACLIST(OPERCMDS) REFRESH

-> PERMIT MVS.DISPLAY.** CLASS(OPERCMDS) ID(MFADMIN) ACCESS(READ)

-> RALTER OPERCMDS MVS.DISPLAY.** NOTIFY(RAM)

Listing the General Resource Profiles

-> RLIST OPERCMDS MVS.DISPLAY.**

-> RLIST OPERCMDS MVS.DISPLAY.** ALL.

Listing dataset Protection in z/OS Mainframe



LISTDSD command is used to list a dataset profile defined to RACF.

-> LISTDSD ID(ram)

- will give info about perticular ID.

-> LISTDSD ID(ram) all

-> LISTDSD dataset('sys1.parmlib')

-> LISTDSD dataset('sys1.parmlib') all

Removing Dataset Protection

The DELDSD command is used to delete the dataset profiles defined to the RACF database.

-> DELDSD|DD prfl_name

-> DELDSD 'sys.**'

Refreshing Dataset Profiles

Using SETR REFRESH command we can refresh the dataset profiles.

Dataset Profiles - Resource Profile in Mainframe



Datasets can be protected using dataset profile.

a). Discrete Dataset

A Discrete dataset profile protects only a single dataset. Usually very sensitive datasets are protected using discrete dataset profile.

Creating a Dataset Profile

-> ADDSD 'usr001.Jcl.ps' UACC(NONE) NOTIFY(usr001)

Permit userID to access the datasets.

-> PE 'usr001.JCL.ps' ID(Demo06) ACCESS(UPDATE)

Change Access Authority.

-> ALTDSD 'usr001.JCL.ps' UACC(READ) NOtify(usr001)

b) Generic Dataset

A generic dataset profile protects more than one datasets. Generic dataset profiles than one datasets. Generic dataset & profiles exploit the similarity in the name of the datasets.

Creating a Generic Dataset Profile

-> ADDSD 'RRSREE.**' UACC(NONE) NOTIFY(usr001)

-> SETR GENERIC(DATASET) REFRESH

Modifying Dataset Protection

-> ALTDSD 'sys1.**' NOTIFY(DAVIN5) UACC(READ)


Allowing users to access datasets.


-> PERMIT|PE 'SYS1.**' ID(MFADMIN) ACCESS(READ)




Resource Profile in z/OS Mainframe Systems



Resource profile is used to protect the resources.

There are three types of REsource profiles.

1. DataSet Profiles

Datasets can be protected using dataset profile.

a. Generic Dataset

A generic dataset profile protects more than one datasets. Generic dataset profiles than one datasets. Generic dataset & profiles exploit the similarity in the name of the datasets.

More about Dataset Profiles

2.General Resource Profiles

RACF Users in Mainframe Computer Systems



The functional elements of RACF are users and groups.

RACF users are identified by alphanumeric userID.

IBMUSER is a default user and it is a member of group SYS1.

1. Adding new users.

-> ADDUSER|AU user01 name(main75) password(UNA) dfltgrp(grp) owner(demo006)

2. Add user with TSO segment.

-> ALU user01 tso(proc(ikjdb2) acctnum(acct#) size(4096))

3. Deleting users

used to delete user from RACF Group

-> DELUSER|DU user01

4. Connecting user to groups

The CONNECT command is used to connect RACF defined users to RACF defined groups.

-> CONNECT|CO usr_id Group(new_grp_ID)

5. Altering the user [changing the Default group]

-> ALU usr_id dfltgrp(new_grp-ID)

6. Removing users from groups.

-> RE usr_ID GROUP(old_grp_ID)

7. Revoke an ID

-> ALU user_ID REVOKE

8. Resume an ID

-> ALU user_ID RESUME

9. Resume an ID with temporary password.

-> ALU usr_ID RESUME password(UNA).

RACF Groups in Mainframe Computer Systems



Groups are RACF Entities with which you associate any number of users.

SYS1 is the highest group which is predefined when RACF is installed.

All groups other than SYS1 have a Superior group.

1. Adding new groups

The ADDGROUP command is used to define new groups to RACF.

-> ADDGROUP|AG grp supgroup(sgroup) owner(demo06).

2. Listing groups

The LISTGRP command is used to list information about a RACF defined group.

-> LISTGRP|LG grp

3. Modifying Groups

The ALTGROUP command is used to alter a RACF defined group profile.

-> ALTGROUP|grp data("demo group") owner(sgroup).

4. Deleting Groups.

The DELGROUP command is used to delete a RACF defined group.

-> DELGROUP|DG grp

RACF - Resource Access Control Facility - Mainframe System



RACF is the IBM Security Management product for mainframe operating system.
RACF - Extream Security Manager(ESM).

Profile - RACF stores all this information about users groups and resources in profiles. A profile is a record of RACF information that has is a record of RACF inforamtion that has been defined by the security administratior.

There are 3 profiles.

1) User Profile

An individual member identified by his unique id and verified using a password.

2) Group Profile

A group is a collection of RACF users who share common access requirement to protected resources or who have similar attributes within the system.

3) Resource Profile

Any information stored on a computer system such as datasets, Terminals, volumes etc.

There are two type of Resouce Profile

a) Dataset Profiles
b) General Resource Profiles

z/890 SHUT DOWN Procedure in Mainframe Systems



Issue the following commands one by one from the master console.

1. P TCPIP

2. C CICS1

3. -Stop DB2

4. P TSO

5. Z NET

6. F BPXOINIT, SHUTDOWN = FORKINIT

7. C LLA - Library look aside facility

8. C VLF - Virtual look aside facility

9. F DLF, MODE = DRAIN - Data look aside facility.

10. P DLF

11. P RMF

12. P FFST - First Failure Support Technology.

13. %STOP - Racf

14. C SYSLOGD1

15. $P INIT - Initiators

16. $P JES2, TERM

17. Z EOD

18. Close the consoles

19. Double click on groups cpc images. The list of images present is displayed.

20. Single Click on the image then Double Click on the Deactivate button which is at the Daily panel and Confirm by clicking OK on the pop up window.

IPL Start up Procedure in z/OS Mainframe System



1. Switch on the HMC and login to the HMC Control or Interface Panel.

2. Then, Click the "Groups" Icon in the "view" section and than click the "CPC Images Icon in the Work area.

3. Select the appropriate LPAR on which you have to load the MVS image and finally, Double Click on the Activate button in the Daily panel which is at the right pane of the HMC window.

4. Similarly, select the LPAR on which you have to load the MVS Image and finally, double click on the LOAD button in the REcovery panel which is at the right pane of the HMC window.

5. Then enter the LOAD ADDRESS, IODF Address and LOADxx member information.

6. Now, Start the emulators by clicking on the console actions in the view area and configure 3270 Emulators button in the group work area.

7. Enter IP's like z8789300@192.168.1.1:1024 and z7676767@192.168.2.10.

8. Select the LPAR and then click on Operating system messages button in the daily panel which will throw some messages which we must respond as per our needs.

9. You need to type oo,cont and then deactivate the duplicate volumes on inappropriate devices by typing 00,D501.

10. Then activate all the consoles using VARY CN(*) ACTIVATE. and issue d r,l to see how to start the JES. For cold start, type oo, CLPA, SYSParm =00. For warm start, type 02, WARM, NOREQ.

11. The the master Console should be activated using VARY 200, CONSOLE.

12. Here you will specify the commands in the order like

-> S RMF
-> DLF
-> S VLF
-> S VTAM
-> S TSO
-> -START DB@
-> S CICS
-> S TCPIP

Types of IPL ( Initial Program Load ) in z/OS Mainframe



1) Cold Start

Any IPL that loads or reloads the PLPA and does not preserve the VIO data sets.
The first IPL after system installation is always a cold start because the PLPA is initially loaded.

Note - IPL with CLPA option.

2) Quick Start

Any IPL that does not reload the PLPA and does not preserve the VIO data sets.

Nore - IPL with CVIO option.

3) Warm Start

Any IPL that does not reload the PLPA and preserve the jourhaled VIO datasets.

Note - Don't specify CLPA or CV

IPL Phases in z/OS Mainframe System



Hardware IPL Phase

The volume where the OS is stored is refered to as the SYSRES volume or the IPLable disk.

IRIM Phase

IPL Resource Initialization Model. The IRIM reads the LoADPARM information. The LOADPARM consists of IODF volume number, LOADxx version, IPL prompt feature and the alternate nucleus id.

NIP Phase

Expands the SQA and the extended SQA creates the pageable link pack area and extended PLPA Loads modules into the fixed link pack area and extended FLPA loads modules into Modified LPA and extended MLPA.
Allocates virtual Storage for the Common service area and extended CSA.

MSI Pase - Master Scheduler Initialization

Master Scheduler initialization routines initialize system services such as the system log and communications task, and start the master scheduler itself.
They also cause creation of the system address space for the job entry subsystem.

Subsystem Initialization Phase - JES2 Phase

Subsystem initialization is the process of readying a subsystem for use in the system.

IPL - Initial Program Load in z/OS Mainframe



- Loading the Operating System to the Main Storage or Main Memory.

- Load Nucleaus to the SysRes Volume.

- Starting the LPAR is called IPL.

Power ON Reset (POR)

Power ON Reset is performed the system reads the IOCDS and checks the connectivity of all hardware devices.

IPL Phases in z/OS

Hardware IPL pahse
IRIM phase
NIP phase
MSI phase
Subsytem Initialisation Phase

More about IPL Phases

GDG - Generation Data Group in z/OS mainframe system



Generation Data groups or GDG's are a group of data sets which are related to each other chronologically and functionally.

These related Data sets share a unique Data set name.

Every GDG data set has a Generation number and version number assigned to each data set.

Example:

'MYLIB.LIB.TEST.G0001V00'
'MYLIB.LIB.TEST.G0002V00'
'MYLIB.LIB.TEST.G0003V00'

Creation of GDG

Before using GDG, we need to create GDG index and model. IDCAMS utility is used to create GDG index.

Creating Model

Once the index has been created, a model data set must be created. This model data set contains specifications for the DCB subparameters for all data sets that will belong to that GDG.

IBM Mainframe Interview Questions



1) What is Control Area ?

A group of Control Intervals makes up a control area. Max size - 1 cylinder, Min size - 1 Track.

2) What is Control Interval Split ?

Not enough space in the control interval the control interval split is happens.

3) What is Control Area Split ?

If no free CI's found in CA it will go for the split of control area.

4) What is GDG ?

Generation Data Groups or GDG's are a group of data sets which are related to each other chronologically and functionally.

Control Interval (CI) in z/OS Mainframe System



VSAM groups Individual Data records in to larger units of storage. These units of storage are called Control Intervals.

A Control Interval is the amount of data transfered between the auxiliary storage and virtual storage.

Control Interval has 4 components.

1) Data
2) Control Interval Descriptor Field (CIDF)
3) Record Descriptor Field (RDF)
4) Free Space.

CIDF - Contains the information about the free space within the CI.

RDF - Contains the information about the records within the data space.

Free Space - The Space between the Records and the Control Information is free space.

Mainframe Interview Questions for freshers



1) What is cluster ?

A cluster is the collection os physical datasets that make up one logical dataset.

2) What is Relative Byte Address ?

The RBA of a record is its displacement from the begining of data set.

3) What is Index ?

Locate the exact Information.

4) What is Control Interval ?

VSAM groups individual Data records in to larger units of storage. These units of storage are called Control Intervals.

5) What is Free Space ?

The Space between the Records and the control information is free space.

6) What is Spanned Records in Mainframe?

Records which are split between control intervals are called spanned records.

7) What is Access Method ?

Access Methods are ways to maximize the effiency of data storage and retrieval.

Data Sets in VSAM - Virtual Storage Access Method


Entry Sequenced Data Set

Records in an ESDS are stored in the order in which they are written and are retrived by addressed access.

ESDS is a sequential VSAM data set.

Key Sequenced Data set - KSDS

Rrecords in a KSDS are stored in key sequence and are controlled by an index, determine the order in which records are stored.

In KSDS, records can be processed both sequentially and randamly.

Relative Record Data Sets - RRDS

Records in an RRDS are located into fixed length or veriable length slots. These record are represented by the Relative Record Numbers(RRN) of their slots.

Records are accessed based on their original position in th file.

Linear Data Sets

LDS is an unstructured VSAM dataset. LDS is a data set containing only a contiguous string of data bytes with no intervening control information.

VSAM - Virtual Storage Access Method in z/OS mainframe System



VSAM is a Data Management System, it is a high performance Access Method. VSAM acts as an interface between processing programs and the operating system.

Access Method

Access Methods are ways to maximize the efficiency of data storage and retrieval.

Access Method Types

1) Queued Sequential Access Method : QSAM
2) Basic Sequential Access Method : BSAM
3) Index Sequential Access Method : ISAM
4) Basic Direct Access Method : BDAM
5) Partitioned Data set / Extended : PDS/E

PDS/E - Released the unused space automatically.

Procedures - Proc and Pend Statements in z/OS



There are two statements,

1) Proc Statement

Marks the begining of a Procedure, Optional for a cataloged procedure, Required for an Instream Procedure.

2) Pend Statement

Marks the End of a Procedure. Name is Optional for a cataloged procedure, Required for an Instream Procedure.

Symbolic Parameters

A symbolic parameter is a symbol proceded by an ampersand that stands for a parameter, subparameter or value.

Marks the procedure more flexible and general purpose.

Procedures in z/OS Mainframe Operating System



A procedure is a set of standard JOB step definitions that can be used repeatedly to perform a function.

Procedures are collection of executable Instruction.

Procedures are Invoded by EXEC Statements.

There are two types of Procedures, They are

1) Cataloged Procedure


Cataloged Procedure is a set of Job Control Statements that are grouped together, given a name, then recorded as a member of a partitioned data set.

2) Instream Procedure


Completely contained within a JCL JOB. String of JCL statements appearing between a PROC and PEND statement within a JOB. Available to only one JOB.

Upto 15 procedures can be defined within a JOB, can be invoked any number of times.

Keyword Parameters in DD Statements



The following Keyword parameters are generally using,

a) DCB

The DCB parameter defines the format type, length of records, and block size for a new data set.

b) DSN

which is an accepted abbreviation for the DSNAME, which identifies the real name of a data set.

c) DISP

which identifies the data set as a new data set ( The Current status of the dataset).

d) SPACE

The space parameter allocates storage for a new data set on a DASD.

e) LABEL

The label parameter specifies, specific information about a tape or Direct access data set.

f) SYSOUT

The Sysout parameter specifies a system output data set and its output class. A system output data set contains the jobs ouput that is to be printed.

g) UNIT

When you are defining a new data set, you may use the UNIT parameter to tell z/OS to place the data set on.

-> A specific device, by specifying a Hardware address.
-> The same device as another data set.


Positional Parameters in DD Statements



In Positional parameters, four parameters are there,

They are

a) Instream Data (*)

The * parameter value begins in-stream data set.

b) Data

The DATA parameter value begins an in-stream data set that may contain statements with // in columns 1 and 2/

c) Dummy

The DUMMY parameter value tells z/OS not to perform any I/O, or disposition processing on the data set.

d) DYNAM

The DYNAM parameter value is supported only to provide compatibility with previous versions of the z/OS.



DD (Data Definition) Statement in Job Control Language



It describes data sets to be used with in individual steps.

There are two parameters in DD statement.

They are,

1) Positional Parameters

In Positional Parameters, four parameters are there,

a) Instream Data (*)
b) Data
c) Dummy
d) DYNAM

More about Positional Parameters

2) Keyword Parameters

In Keyword Parameters, six and more parameters are there,

a) DCB
b) DSN
c) DISP
d) SPACE
e) LABEL
f) SYSOUT
g) UNIT

More about Keyword Parameters

Positional Parameters in EXEC Statement


There are two parameters are there.

They are,

a) PGM

The PGM parameter identifies the program the system is to run.

b) PROC

The Proc or procedure name identifies the cataloged or in-stream procedure the system is to run.

Keyword Parameters in EXEC Statement

There are three parameters are there.

They are,

a) PARM

Passes parameters to the program that is being executed.

b) REGION

Use the REGION parameter to override the default amount of Storage space (KB or MB) that the System allocates to a particular job or job step.

c) COND

In a Multi-step job, use the COND parameter to specify the conditions that allow the system to bypass a step by testing return codes from any or all previous steps. You can code upto 8 comparisons.

As an alternate way IF/THEN/ELSE

EXEC Statements in Job Control Language



EXEC Statement

It marks the begining of a job step and specifies the name of the program to be executed.

There are two parameters of EXEC Statements. They are

i) Positional Parameters

Positional parameters are having two type of parameters.

a)PGM
b)PROC

And You can see the topic Positional Parameters in EXEC Statement

ii) Keyword Parameters

Keyword Parameters are having three parameters called PARM, REGION, and COND.


Keyword Parameters in Job Statement



a) CLASS 

CLASS specifies the jobs Class. Indicates the type of JOB submitted to the system.

Example: CLASS = A -> test jobs  B -> production jobs

b) MSGCLASS

Determines the output device to which system messages and JCL messages are written.

Normally A for printer, T for Terminal.

c) MSGLEVEL

MSGLEVEL = (JCL , allocations)

MSGLEVEL specifies the printing of JCL statements and allocation messages.

JCL [0 - No allocation messages 1 - All allocation messages]

d) TIME

TIME [M,S] coded on the job statement sets the limit for the entire job.

- Specifies the maximum CPU time for a JOB
- System will automatically cancel the JOB if it is execution time exceeds the specified time.

e) PRTY

Assifning priority to jobs belongs to same class, it can be 1 to 15.

f) NOTIFY

- Used to direct the MAXCC value to user
- can be user id or &SYSUID.

g) TYPERUN - SCAN/HOLD

SCAN - Scans for JCL syntax error only.
HOLD - Holding job for later execution.
RESTART - Enables execution of job from particular step.

Positional Parameters in JOB Statement



There are two positional parameters are there

a) Job Accounting Information

Identifies account number which will be billed for CPU time.

b) Programmer Name

Identifies the author's name.

Example:

(1989, Name)

where,

1989 - Account Number

Name - Authors Name

JCL Statements in Mainframe Systems


There are three types of JCL Statements are there,

1. JOB

2. EXEC

3. DD

1. JOB Statement

It marks the begining of a job and identifies the job name.

Job Statement contains two parameters,

a) Positional Parameters

b) Keyword Parameters

Positional Parameters

There are two positional parameters are there. They are,

i. Job Accounting Information

ii. Programmer Name

More About Positional Parameters


JCL - Job Control Language in Mainframe



JCL - Job Control Language provides the operating system with information about the resources, programs and data neccessary to complete the job.

JCL acts as an interface between programs written in COBOL and Operating System.

What is JOB?

Collection of unit of tasts is called JOB.

Batch Processing - is used to execute one or more programs in a specified sequence with no further interaction by a user.

What are JCL Statements ?

1. JOB Statement

2. EXEC Statement

3. DD Statement

More About JCL Statements

Wednesday 13 February 2013

Returning Values from a Function in C programming



Just as data can be passed to a function, so also, data can be passed back from a called function to its caller.

In C, functions can return values through the return verb as illustrated in the following example:

main()
{
int x, y, value;
scanf("%d %d", &x, &y);
fflush(stdin);
value = sun(x,y);
printf("Total is %d \n", vlaue);
}
sum (a,b)
int a,b;
{
return a + b;
}

In this example, the function sum() sends back the value of a + b to the function main(). The value returned to main() from sum() is stored in a variable called value, the value of which is printed out through the printf() statement in main().

The return statement not only sends back a value to a caller function, but also returns control to it.

Note that a function can return only one value, though it may return different values depending on certain conditions.

C assumes that the value  returned is an int type value. In case a function has to return a value which is not an integer, then the function itself has to be declared of the specific data type that it returns.

Passing Arrays to Functions in C Programming



Arrays are inherently passed to functions by the call by reference method. for instance, if an array called num_array of size 10 is to be passed to a function called stringfunc(), then it would be passed as follows:

stringfunc (num_array);

Recall that num_array is actually the address of the first element of the array. So, this would be a call by reference. The parameter of the called function, say, number_list could be declared in any of the following ways:

stringfunc(number_list)
int number_list[];
{
--
--

]

OR

stringfunc (number_list)
int number_list[10];
{
--
--
}

OR

stringfunc (number_list)
int *number_list;
{
--
--
}

Call by Reference in C Programming Language



Call by reference means that the called function should be able to refer to the variables of the caller function directly, and not create its own copy of the values in different variables. This would be possible only if the address of the variables are passed as parameters to the function.

Consider the same program written using call by reference:

main()
{
int num1, num2;
char operator;
printf("Enter 2 numbers and an operator\n");
scanf("%d%d%c", &num1, &num2, &operator);
fflush(stdin);
calc(&num1, &num2, &operator);
}
calc(val1, val2, oper)
int *val1, *val2;
char oper;
{
switch(oper)
{
case '+' : printf("%d", *val1 + *val2);
break;
case '-' : printf("%d", *val1 - *val2);
break;
case '*' : printf("%d", *val1 * *val2);
break;
case '/' : printf("%d", *val1 / *val2);
break;
default: printf("Invalid operator \n");
}
}

In this program, the addresses of the variables num1, num2 and operator are passed as parameters to the function calc(), instead of their values.

Invoking Functions in C Programming Language



In C programs, functions that have parameters are invoked in one of two ways:

1). Call by value

2). Call by reference

These will be illustrated through the example of a program called computer that takes two numbers and a mathematical operator as input and perfoms the appropriate arithmetic operation on the numbers.

Call by Value

Consider the following code for the problem statement memtioned:

main()

{
int num1,num2;
char operator;

printf("Enter 2 numbers and an operator\n");
scanf("%d%d%c", &num1, &num2, &operator);
fflush(stdin);

calc(num1, num2, operator);
}

calc(val1, val2, oper)
int val1, val2;
char oper;
{
switch(oper)
{
case '+' : printf("%d", val1 + val2);
break;
case '-' : printf("%d", val1 - val2);
break;
case '*' : printf("%d", val1 * val2);
break;
case '/' : printf("%d", val1 / val2);
break;
default: printf("Invalid operator \n");
}
}
In this program, values entered for the variables num1, num2 and operator in the main() function are passed to the function calc().

Parameter of a Function in C Programming



The term 'parameter' has been introduced earlier. To review, consider the following printf() statement:

printf("%d", value);

The printf() function expects two pieces of information:

1. The format(s) in which data is to be printed.
2. The variable(s) whose value(s) is/are to be printed in the specified format(s).

These are the parameters of the function printf().

Thus, parameter(s) of a function is/are the data that the function must receive when called or invoked from another function.

Not all standard functions require a parameter. An example is getchar(). Similarly, user-defined functions may or may not have parameters.

Consider the following examples:

main()
{
disp_head();
}

disp_head()
{
printf("Employee report");
}

The function disp_head() in program does not expect any data when invoked.

What is Functions in C Programming Language ?



Functions are the building blocks of C. All programs definitely consist of one function - main() - and inevitably refer to, or, in programming terminology, call or invoke standard functions of C such as printf(), scanf(), etc. as well as user-defined functions.

Advantages of Functions

Besides the obvious advantages of

-> Reusability, and
-> Structing of programs

functions also provide programmers a convenient way of designing programs in which complex computations can be built into the functions. Once properly designed, a programmer does not have to bother about how the calculations are done in the function; it is sufficient for him to know what it does. Thus, to the programmer, the function itself would be like a black box. The programmer has to the function.

The use of functions would probably save a programmer the often nerve-racking experience of debugging a program that refuses to 'function' properly.

String - Handling Functions Using Pointers C Programming Language



Now that we have laid the groundwork for understanding the concept of pointers, we will write a few functions to manipulate strings using pointers.

#include <stdio.h>
main()
{
char *ptr,str[20];
int size=0;
printf("\nEnter String :");
gets(str);
fflush(stdin);
for(ptr=str; *ptr != '\0' ; ptr++)
{
size++;
}
printf("String length is %d", size);
}

Two Dimensional Arrays and Pointers in C Programming language



Extending the logic of declaring one-dimensional character arrays, we can also declare two-d charater arrays.

char *things[6];

Individual strings can be initialised by separate assignment statements since each element of this array is a pointer.

things[0] = "Raindrops on roses";
things[1] = "And Whiskers on kittens";
things[2] = "Bright copper kettles";
things[3] = "And Warm woollen mittens";
things[4] = "Brown paper packages tied up with strings";
things[6] = "These are a few of my favourite things";

The third line of the song can be printed by the following statement:

printf("%s", things[2]);

Now, let us complicate things a little further and apply pointer arithmetic to two-d arrays.

Consider the following declaration:

int num[3][4] = {
{3,6,9,12},
{15,25,30,35},
{66,77,88,99},
};

This statements actually declares an array of 3 pointers (constant) num[0], num[1], num[2] each containing the address of the first element of three single dimensional arrays.

Pointer Arithmetic of incrementing and decrementing



Arithmetic operations of incrementing and decrementing can be performed on pointers. In fact, pointer arithmetic is one of the reasons why it is essential to declare a pointer as pointing to a certain datatype so that when the pointer is incremented or decremented, it moves by the appropriate number of bytes. Thus, a simple satement like

ptr++;

does not neccessarily mean that ptr now points to the next memory location. What memory location it will point to depend upon the datatype to which the pointer points.

Consider the following example:

#include<stdio.h>

char movie[] = "Jurassic Park";

main()
{
char *ptr;
ptr=movie;
printf("%s", movie);

printf("%s", ptr);

ptr++;

printf("%s", movie);

printf("%s", ptr);

ptr++;

printf("%s", movie);

printf("%s", ptr);

}

Two Dimensional Character Arrays in C Programming Language



Two-d character arrays are typically used to create an array of strings. Manipulating a character two-d array is however, slightly different from manipulating an integer or float two-d array. This is because a character two-d array is likely to be accessed in terms of strings rather than elements, and hence requires only the row subscript. Individual elements can be accessed as usual by specifying both subscripts.

Consider the following example:

#include <stdio.h>

char books[][40] = {
"This is first",
"This is second",
"This is third",
"This is forth"
};

main()
{
int num;
printf("\nEnter a semester number");
scanf("%d", &num);
fflush(stdin);
if(num>=1 && num<=6)
{
num--;
printf("Your book for thi semester is %s", books[num]);
}
else
printf("\nWrong semester !");
}

Consider the need to store the marks of the students belonging to a batch, in various subjects. The list of student names are stored in a two dimensional character array called student. The list of subjects is also stored in a two dimensional array called subject. The details of the marks of each student in each subject are going to be stored in a two dimensional integer array called marks.

What is Task and Transaction in Mainframe Systems



Task - The tast is a unique, basic unit of work scheduled by the OS or CICS. A task can,
* Read from and write to the terminal.
* Read and write files.
* start another task.

Transaction

A transaction is an entity which initiates execution of a task. In CICS, every transaction is identified by a 4 character transaction identifiers (TRANSID). The transaction IDs are placed in the DCT by the system programmer.

CICS Features - Multitasking

As dicussed earlier a task is the execution of an application program for a specific user. Multitaking refers to running multiple tasks at the same time. within CICS, tow or more.

Multithreading

Multithreading allows two or more users can access the same copy of a program at the same time. CICS accomplihes this by providing a seperate copy of working storage for each user running the program.

CICS Nucleus in Mainframe Computer System



1) The CICS Nucleus consits of a set of control programs and control tables.

2) The control programs are supplied by IBM.

3) The Control tables are userdefined.

IBM suplied Control Programs

a) DFHSIP
b) DFIHTCP
c) DFHSCP
d) DFHFLP

User defined Control tables

1) PPT
2) FCT
3) TCT
4) TST
5) DCT
6) JCT
7) PCT

Defining resouces into the control tables add a new entry into the control tables. The resouces entries can be made in any of the following ways.
1) Through a CICS transaction called CEDA.
2) Through batch using DFHCSDUP utility process.

CICS System Services



1) Data Communication Fuctions

Interface between CICS and terminals, To Interface Telecommunication access methods. To free application programs from the terminal hardware.

2) Data Handling Functions

Interface between the CICS and Data, To Interface with data access methods -VSAM, To Interface with databases Access Methods - DB2.

3) Application Programming Services

Interface between the CICS and Application Program (COBOL)
1) Command level translator,
2) Execution diagnestic facility(EDF).
3) Command interpreter(CECI).

4) System services

1)Interface between the CICS and Os,
2)Program Control(Load, RELEASE)
3)storage Control
4)Task Control

5) Monitoring Functions

1) Monitor various events within CICS.
2) Provides statistics to be used for system tuning.
3) Offline program DFHSTUP can be used for statistics informations.

CICS - Customer Information Control System



1) CICS is an Online Transaction Processing System

2) CICS acts as an Interface b/w Application software and z/os.

3) CICS is an Database / Datacommunication control system.

CICS Introduction:

Macro level CICS - Initial version assembler macro to request CICS services.

Command level CICS - High level language version, commands to requests CICS services.


What is CICS ?

CICS is a transactional subsystem of z/os that can,

1) Run online applications.
2) Run same time, many users, same applications.
3) Manage the sharing of resourcing
4) Ensure integrity of data (Correctness of data).
5) Prioritize execution withfast response.

Protechting data through RACF




1) Add RAcF groups to control datasets that use the default DB2 qualifiers.

2) Create generic profiles for different types of DB2  datasets and permit their use by DB2 started tasks.

3) Permit use of the profiles

DB2 Security in Mainframe Computer Systems



DB SEcurity:

1)Primary Authorization ID
2)Secondary Authorization ID
3)SQLID

These three security methods are eligible to secure data access.

Method 1:

You can secure data access by means of privilleges either specific functions. The privillege can be implicit or explicit.

Method 2:

You can secure your DB2 dataset access by means of implimenting RACF.

Method 3:

You can secure DB2 data access by means of encryption technique.

Implicit:

By Default or By Automatic. The user has certain level of privilleges by the means of implicit. If I am a owner or creater of an object by default i have read, delete, update, insert and create index. Suppose I'm a users of others object then permission to access a data done by means of explicit privileges.

(Grant All on table tablename to public;)

Starting and Stoping DB2 Databases



Starting DB2 Databases:

RW - Allows programs to read from and write to the database.
RO - This Read Only.
UT - This access code only allows access to this database by DB2 utility programs.
FORCE - This option is seldom used, as it does not generate database integrity.

Stoping DB2 Databases

STOP DATABASE (*) - stops all database which you have the authority to stop.
STOP DATABASE(database name)

stops the one database specified.

STOP DATABASE(DATABASE NAME) PART(N)

stops a particular database partition.

STOP DB(database name) SPACE(tablespace name)

stops the specified TS.

Controlling the IRLM in Mainframe



The IRLM monitors and manages the mechanism that DB2 uses to ensure databases integrity. This mechanism is known as locking. The IRLM, which DB2 connected to, is defined in the DB2 parameter member DSNZPARM in SYS1.PARMLIB.

The name identified in this member is the IRLM procedure name and is used as part of the OS/390 modify(F) command.

The following OS/390 commands are used to manage the IRLM.

F procname, ABEND, NODUMP.

Requests an abnormal termination of the IRLM, where procname is the name of the IRLM.

F procname, status

Displays the status of the IRLM.

START/STOP MRLMPROC

starts or stops th IRLM.

Console Authority in Mainframe



Auth specifies the group of operator commands that can be entered from the console.

You can change the AUTH using Vary command the syntax is as follows

VARY CN(console-id), AUTH=<authority>

There are six types of authority they are as follows

* MASTER
* INFO
* SYS
* IO
* CONS
* ALL

MASTER indicates that this is a console with master-level authority. The system uses the first online console in CONSOLXX with MASTER authority as the master console. When the first console in CONSOLXX with MASTER authority is not online, then the ROUTCODE, UD, AND LEVEL attributes of this first console are merged with the attributes specifed for the console that is selected as the master console.

INFO specifies that any informational commands can be entered from this console.

SYS specifies that system control commands and informational commands may be entered from this console.

IO specifies that I/O control commands and informational commands may be entered from this console.

CONS specifies that console control commands and informational commands may be entered from this console.

ALL specifies that information, system control, I/O control, and console control commands may be entered from this console.

Console Monitoring in Mainframe Computer system



Computer operators are responsible for monitoring and managing the operations of MVS.

Computer operators use consoles to

* Issue system commands
* Receive system messages

Consoles cannot be used for any other input/output purposes (such as TSO, CICS, etc.).

MVS sends messages via the console that

* Informs you the status of the job
* Request that you perform a required action, such as mounting tapes or catridges

Consoles provid a communication link between you and MVS, JES2/JES3, VTAM, other system components and application programs.

OS/390 Storage in Mainframe system



Logicaly an OS/390 system consists of DASD, one or more CPUs and I/O devices.

Central or Main Storage - is directly addressable by CPU where both programs and data must be loaded before processing.

Expanded Storage - may be used to relieve the central storage when it is heavily utillized. This is done by moving data from the central to the expanded storage. The combination together is called processor storage. The storage is organized in 4k byte blocks. This is also the smallest addressable unit and is called a frame.

Virtual Storage - consists of 4KB blocks called pages. A page may be stored in central, expanded or auxiliary storage. When residing in central or expanded storage it is referred to as frame while in auxiliary storage it is referred to as slot.

Dynamic Address Translation - is the process of translating the virtual address to the corresponding central during storage reference.

Swapping - is the process of physically or logically removing a user from central storage. This means moving all of his currently active data and programs to expanded storage or writing them to swap or page data sets or marking them as swapped.

Address Space - The sequence of virtual addresses associated with a virtual storage is called and address space. An address space can contain 2GB of virtual Storage.

Multitple Virtual Storage - is the basic concept of the OS/390 operating system.

Data Spaces and Hyper Spaces - are similar in that, both are areas of virtual storage that can be created by the system upon user request. The size of those spaces can range from 4KB to 2GB depending on the users request. Unlike address space, a data space or hyper space contains only user data or user programs stored as data. Program code cannot be directly executed in a data space or hyper space.

Basic Mainframe Technical HR Interview Questions



What is Mainframe Storage Management ?

Storage Management is basically provided through OS/390's operating system MVS which organizes the available storage in such a way that the usable storage appears to be larger than what is actually available. To accomplish this it provides various mechanisms to move data and programs between different kinds of storage thereby virtually enlarging the storage for each user.


What is Workload management in Mainframe ?

Workload Mangement offers great number of resources to its users. The work has to be described and submitted to the system to allow it to schedule the work, allocate proper resources and to allow concurrent resource access.

What is Data management in Mainframe ?

Data Mangaement provides basic means for storing and retrieving data and programs on/from different kinds of storage devices.

Introduction to OS/390 - Mainframe System



An IBM System 390 consists of hardware and software products. The hardware has a central processor complex (CPC) that includes the central processor, storage, channels etc. The Software consists of system application programs, end-user application tools etc. The primary program executing on the system is an operating system is an operating system such as OS/390.

The OS/390 operating system manages the instructions to be processed and the resources required to process them. A single copy of OS/390 running on a single processor system is called a uni-processor.

By adding more processors to a CPC, multiple program instructions can be processed simultaneously. A multiprocessor system running under a single OS/390 image is referred to as non-partitionable multiprocessor.

That PR/SM feature allows multiple logical partitions such as:

* processor
* storage
* channel paths

A symplex (Systems complex) consists of two or more MVS systems residing on one or more CPCs. It is the basis for a simplified multi-system management. In a sysplex, an installation can view multiple MVS systems as a single entity. The enhanced parallel-sysplex supports communication and data sharing among more systems, thus dynamically balancing workloads.

Basic Interview Questions in Database - DBMS



What is Hierarchical Database System ?

Hierarchical database system keeps the data in teh form of a parent child relationship. The datas is organised as a Tree structure. The origin of a data is the root of the data tree. The data occupies with different level of the particular branch of the tree called the node. The last node in the structure is called leaf. The high level node points to zero or more node in the next level. Each child has pointers to numerous siblings.

What is Network Database System ?

In this model data are represented by a collection of records and the relationships among data are represented by links NDS is supporting Many to Many relationship.

Disadvantages of Network Database System

1) Pointers create the complexity of the model.
2) It requires more space for keeping pointer value.

What is Relation Database System ?

A data-model in which both data and their relationships are represented by means of tables is called Relational model.

The relation is the only data structure used in this model to represent both entities and their interrelationships. A relation is a two dimensional table with a unique name.

Each row of a table is called a tuple and each column of a table is called an attribute. The set of all possible values in an attribute is called the domain of the attribute.

Disadvantages of Relation Database System

1) Resuability of the structure is not possible
2) Alteration of the structure is difficult
3) Maintenance of the structure is a continuous process

What is Object Based Relational Model ?

In this model the data are organized as an object. Each object has a set of value based on their class. The data structure of the object is called Class.

Advantages of Object Based Relational Model

1) Reusability of the structure is possible.
2) This model supports to define interface for the application

What is Database Models ?



Database models is a technique to store the database in a DBMS. Each DBMS follows different database model. Database models can be classified into two groups. They are,

1) Object - based logical model
2) Record - based logical model

1) Object - based logical model : In this model, the data, relationship and constraints are defined as a collection of ideal tools.

2) Record - based logical model : This model describes the data structure and access techniques of a DBMS.

File Management system in Database Management System

File Management System is the first method used to store the data in a database. In this model the data items are stored sequentially in a file. If we want to search an item in a file, the search starts from the first record and items are checked sequentially till the search item is matched.

Disadvantages of File Management System

1) Searching and retrieving a record is a very tedious process because it supports only sequential access.
2) Updating the data items takes more times.
3) It is not supporting directly for altering the file structure.
4) Inserting and deleting process is not easy.

Relationship between data in Database Management System



Relationship is an association between the entities. A relationship may associate an entity with itself.

There are are four different types of relationships among the entites. They are,

1) One - to - One
2) One - to - Many
3) Many - to - One
4) Many - to - Many

One - to - One Relationship in Database Management System

A relationship between one entity to only one other entity is called One - to - One relationship.

One - to - Many Relationship in Database Management System

A relationship between one entity to more entity is called One - to - Many relationship.

Many - to - One Relationship in Database Management System

A relationship between more entities with one entity is called Many - to - One.

Many - to - Many Relationship in Database Management System

A relationship between by more entities with more entities is called Many - to - Many.

Entity & Attributes in Database Management System


Entity in Database Management System

An entity is an object or a thing such as person, place, concept, activity about which an Organization keeps information. Graphically entity is represented as a rectangle with name.
Example: in College system Student, teacher etc, are called entity.

Attributes in Database Management System

An attribute is the characteristic properties of an entity. It describe the entity. Graphically attributes are represented an an ellipse with name.

Services of Database Management System



A DBMS provides the following servicess to do the activities mentioned previously. Let us see some of the services.

1. Data Definition: This is a method of defining data and its storage.

2. Data maintenance: This method verifies whether each record has fields containing all information as defined using data definition.

3. Data Manipulation: Data manipulation allows to insert, update, delete and sort data in the database.

4. Data Display: Data display allows viewing the data in the database.

5. Data Integrity: this method verifies the integrity or accuracy of data stored in the database.

What is RDBMS in Database concepts



RDBMS is stands for Relational DataBase Management System. Proper management of data is very essential to run any concern successfully. Before the emergence of RDBMS , all are used DBMS to manage data. But most of the concerns felt that DBMS to was not efficient to meet their expectations. As a result, application developers began to move their attention to other environment like COBOL and C.

What is DataBase Management System

A Database Management System is a collection of interrelated data together with a set of programs to access the data.

The Collection of interrelated data is called the Database.

Any database system consists of two parts. They are

a) Database Management System
b) Database Application

The Database management system is required to organize and maintain the data.

The Database Application is a program to retrieve, insert and update the data in the system.

Interview Questions - Data Structure



1) What is the significance of a Primary key?
2) What is the primitive data type ?
3) What are the data structure operations ?
4) What is an linear array?
5) What is an two dimensional array?
6) What is a pointer?
7) How Strings are represented in memory?
8) How 2D arrays are represented in memory?
9) Explain Pointer array?
10) Distinguish linear search and binary search.
11) Explain the concept of binary search.
12) Explain the representation of linear array in memory?
13) How will you insert and delete elements from a linear array.
14) Expalin linear search with example.
15) Explain string processing
16) Explain pattern matching algorithm with example
17) Explain Bubble Sort with example
18) Explain binary search with example
19) Expalin Traversing a linear array.

String Operations in C Programming Language



String is a sequence of characters in c programming. The important string operations are,

1) Substring
2) Indexing
3) Concatenation
4) Length

Substring in C Programming Language

A group of consecutive characters in a string is called substring. The following three attributes are required to identify the substring in a string.

1) name of the string
2) starting position of the substring
3) length of the substring.

The general form is
substring (str, start, length)

Indexing in C Programming

Indexing is an operating to find the starting index position of first matched substring in a given string. It is also called pattern matching. The substring is called pattern. If the pattern is not available in the given string, then the index values is zero. The general form,

index (str, p)

Concatenation in C Programming language

Concatenation in an operation to join two string values. This gives a single string connecting first string characters followed by second string characters. The general form is

S1 // S2

Length in C Programming Language

Length is an operation to find the number of characters in a string. Ther general form is,

lenght(str)
where str - string of characters

Constants & Variables in C Programming Language



String constant is a sequence of characters within single or double quotation marks.
Example:
'Welcome' "Welcome"

Variables in C Programming Language

Each programming language has its own rules for representing character variables. There are three types of variables. They are,

1) Static
2) Semistatic
3) Dynamic


Static Variables in C programming Language

A static data type is a data type whose length of variable is fixed before executing the program. We cannot change the length during run time.

Semistatic Variables in C Programming Language

A semistatic data type is a datatype whose length of the variable can be varied during run time. But the length should not exceed the already fixed value.

Dynamic Variables in C Programming language

A dynamic data type is a data type whose length of the variables can be changed during run time.



Pointers in C programming Lnaguage



Pointers are variables that hold the memory address of other variables. This can be explained by the following

int a = 5;

Let us assume that 1001 is the address of the variable a and this numeric address is stored in another variable named as b having address 1020.

We can access the values of variable a by using the pointer variable b.


Advantages of Pointers in C Programming

1) Pointers increase the execution speed of the program.
2) pointers enable us to access a variable that is defined outside the function.
3) pointers are used to pass information back and forth between a function and its reference point.
4) Pointers reduce the length and complexity of a program.

Two dimensional array representation



In many applications the data has to be represented as rows and columns. The representation of data in memory as rows and columns is called 2-D array. The general form is

datatype name[row size][column size];

Range :

The size of the row is called row range and size of column is called column range.

the maximum elements in a 2-D array are got by multiplying row range and column range.

Maximum elements in a 2-D array = row range column range

Two types of Data Structures to store data ?



Ther are thow types of data structures to store data. They are,

1) Linear
2) Non-linear

Linear DataStructure: In linear data structure, data items are organized in a sequential or in linear list order. There are two ways to represent linear structure in memory. They are,

1) Arrays
2) Linked list

In an arrays structure the data items are represented by contineous memory locations. In linked list structure the data items are represented using pointers or links.

Non-linear Data Structure: Data items are oraganized in non-linear order. There are two ways to represent non-linear structure in memory. They are,

1) Trees
2) Graphs

Data Structure Operations



Operation means processing the data in the data structure. The following are some important operations.

1) Traversing - to visit or process each data exactly once in the data structure.
2) Searching - to search for a particular value in the data structure for the given key vlaue.
3) Inserting - to add a new value to the data structure
4) Deleting - to remove a value from the data structure
5) Sorting - to arrange the values in the data sturcture in a particular order.
6) Merging - Join two same type of data structure values.

Tuesday 12 February 2013

What is Data Structure or Data Oraganization ?


Oraganization refers the way in which the data is represented or stored in the memory. This is also called data structure. Data can be oraganized in many ways. They are,

1) Primitive data types
2) Arrays
3) Linked List
4) Trees
5) Graphs
6) Files

If the data contains a single value, this can be organized as a primitive data type. If the data contains a set of same data type values, then this can be organized consecutively using arrays. If the data contains a set of same data type values, then this can be organized not in consecutively using linked lists.

If the data contains a set of same type of values with a hierarchial relationship, then this can be organised using trees. If the data contains a set of same values with a relationship between pairs of values, then this can be organized using graphs.

If the data contains a set of different values, then this can be organized using files.

Files in Data Structure and Data Organization


A file is a collection of related records (entity). Each record contains a set of fields (attributes). Each field refers a numeric or non-numeric values.

A set of minimun number of attributes which are used to idendify a record in a file is called key (primary key).


What is Data Structure or Data Oraganization ?

Oraganization refers the way in which the data is represented or stored in the memory. This is also called data structure. More About Data Structure

What is Primitive Data Types in Data Structure ?


What is Primitive Data Types in Data Structure ?

The different primitive data types are

1) integer
2) float
3) double
4) character
5) boolean

Using this we can represent a single value. The range of values in each primitive data type is different in different computer languages. For example in C language the range of integer value is -2^31 to 2^31 - 1.

Symbolic constants and constant qualifiers in C++ programming


Symbolic constants and constant qualifiers in C++ programming

Symbolic constant is a quantity which does not change during the execution of the program. Constant qualifiers are keywords used to define a quantity as symbolic constant. The qualifiers are

1) const.
2) enum.

steps and rules:

1) Const must be initialized.
2) Const is local to the function where it is declared.
3) By the qualifier extern along with const, it can be made global.
4) If data type is not given it is treated as integer.

What is Typedef in C++ programming ?


What is Typedef in C++ programming ?

Typedef is a keyword. This is used to define a new name for an existing data type. The general form is

typedef datatype newname;

where,
typedef -keyword
datatype - valid datatypes such as int, float, char, etc.
new name - valid C++ name for the data type

In C++ there is no need to specify the keyword typedef for enum, structure and union data types.

Difference between unions and structures


Difference between unions and structures

1) A union can provide storage for one member at a given time. But a structure can provide storage for all members.

2) The amount of space allocated for union is based upon the member which requires the largest memory space. But in structure each member is given memory space.

3) In Union at one time we can refer any one variable. But in structure we can refer all the variables.

Union in C++ programming Language



Union is like a structure data type in which all the members share the same memory area. The general form is,

union tag-field
{
datatype member1;
datatype member2;
------
------
datatype membern;
}variable1, variable2 ...variablen;

Example:
Consider the following union declaration
union example
{
char name[15];
int number;
}student;

This declares student as a variable to the union named example having two members. The members are accessed as
student.name
student.number
Because of the property that all members share the same memory space, the compiler allocates a memory space that is large enough to store the largest variable type in the union. In our declaration the 15 character string requires more memory than the integet quantity. so the compiler allocates 15 bytes to the union. This area will be shared by the two variables student.name and student.number.

Users of Union:

1) Unions needs less memory space
2) They are useful for applications involving number of variables, where values need not be assigned to all elements at one time

Structre in C++ Programming Languages



A structure is defined as a data type to represent different types of data with a single name. The data items in a structure are called members of the structure.

Defining a structure:

A structure definition contains a keyword struct and a user defined tag-field followed by the members of the structure within braces. The general form is

struct tag-field
{
datatype member1;
datatype member2;
-------
-------
datatype membern;
}

where,
struct  - keyword to define structure
tag-field - name of the structure - valid C++ name
datatype - valid datatypes such as int, float etc

Steps and Rules:

1. Tag-field is the name given to the structure
2. Each member definition should be terminated with semicolon
3. Since structure definition has compound statements, it should have its own opening and closing braces.
4. The semicolon after the closing brace is a must.

Advantages of Enumeration in c++ Programming



Advantages of Enumeration in c++ Programming

a. With this we can assign more than one constant value to a single user defined name.
b. Internally the values of constant are 0, 1, 2, ... n-1.
c. We can explicitly change the value of constants.
d. Arithmetic operations are possible on enumerated type variables.

User defined data types in C++ Programming Language



User defined data types are data types defined by the user. They are

1) Enumeration
2) Structure
3) Union
4) Class

1) Enumeration

This allows us to define our own data type with predefined values. The general form is,

enum userdefined_name
{
value1,
value2,
---
---
valuen
};

The default values 0,1,2,.... n-1 can be changed by giving value in the declaration as

enum userdefined_name { value1=20, vlau2=3 .... valuen=50 };

Once the enumeration data type is defined , we can declare variables of this data types. The general form is

userdefined_name variable1, variable2, ... variablen;

The variables variable1, variable2, ... variablen cannot take values other than value1=20, vlau2=3 .... valuen=50. The userdefined-name should be the same name as used in the definition.


Type Casting in C++ Programming Language



It is a process of converting one data type into another. There are two types of data type conversion. They are,

1) Explicit conversion
2) Implicit conversion

1) Explicit conversion

It is a process of converting one data type into another explicitly using cast operator. The general form is

newtype (variable or expression);

(or)

(new type) variable or expression;

2) Implicit conversion or automatic conversion

If an expression contains different type of operands, the lower data type operands are automatically converted to higher data types. This conversion is called implicit conversion. The lower data types are data types which occupies less memory space and higher data types are data types which occupies large memory space.

float x;
x=6 + 8.3;

The operands 6 and 8.5 in the expression are of different data types. But during execution the integer data 5 is automatically converted into float type and the operation is performed. So the result is 14.5.

Data types in C++ Programming Language



C++ data types can be classified as

1) Basic data types
2) User defined data types
3) Derived data types

Basic data types in C++ Programming Language

These data types are already defined in the language. They are,

1) char
2) int
3) float
4) double

The following keywords are prefixed with the basic data types to produce new data types. These keywords are otherwise called as modifiers.

1) signed
2) unsigned
3) long
4) short

Special basic data type:
Void is a special basic data type. The compile will not allocate any memory space for this data type. This data type is used to

1) define functions.
2) define parameter passing

Example:

1. void fun1(); - This means the function fun1 will not return any value.

2. int fun2(); - This means the function fun2 will not receive any parameters. But returns an integer type value.

Constants in C++ Programming Language



Constant is a quantity which does not change during the execution of the program. The different type of constants are,

1) Integer constant
2) Floating point constant
3) Character constant
4) String constant
5) Wide - character constant

Example:

345 - Integer
110.21 - Floating point
'B' - Character constant
"Name" - String constant
A 'CD' - Wide character constant

Dynamic initialization of variables



Initialization of variables during run time is called dynamic initialization of variables.

Example:

int l;
cin>>l;
float avg=l/10;

The variable avg is initialized only during run time, because the value of l is available during run time only.

Declaration of variables in C++ Programming Language



Variable is a quantity which changes during the execution of the program.

All variables present in the program must be declared before it is used. The declaration can also be done before the first use of the variable. The general for is

datatype variablelist;

Example:

1) int a, b, c;
This declares a, b, c as integer variables and allocate memory space.

2) int n;
for(int j=0; j<=n;j++)

This is valid because j is declared as int j before it is used.

Identifiers in C++ Programming Language


Identifiers are names given to variables, functions, arrays and other user defined structure. These are user defined names.

Steps (how to do):

1) Identifiers are formed with alphabets, digits and a special character underscore (-).
2) The first character must be an alphabet.
3) No special characters are allowed other than underscore.
4) They are case sensitive. That is AA is different from aa.
5) There is no limit for the number of characters.

Example:

1) The following are some valid identifiers
   A0, BASICPAY, basicpay, TOTAL_PAY, B12.
 
2) The following are invalid identifiers


Commenting and UnCommenting a Program C Programming



Comment statements are non-executable statements. These statements are used to increase the readability and understanding of the program. A comment statement can be included anywhere in the program. There are two types of comments. they are,

1) Multiline comment
2) Singleline comment

All multiline comments should start with /* and end with */. No  space is allowed between * and /.
All singleline comments should start with //. No space allowed between /and /.

Example:

1) /* program to find the sum of three
numbers */

2) // program by Jhon, Ramu and Rahmon.

Namespace in C++ Programming Language



Namespace is a keyword used to create a memory area. In this area the programmer can define various program elements such as variables, functions, classes etc. These program elements can be used any where in the programs like global variables.

Defining a namespane
The general form is,

namespace name
{
statement-1;
statement-2;
---------
statement-n;
}

Keywords in C and C++ Programming Language



Keywords are words which belongs to C++ language. They have standard predefined meaning. These words should be used only for their intended purpose. The users have no right to change its meaning. Keywords should be written in lowercase.

New keywords in C++

C++ language contains all the keywords in C language. In addition to this some more keywords are added to make C++ language as an object oriented language. These keywords are called new keywords. In other words new keywords are words which belongs to C++ language only.

Examples for Keywords:

1) New keywords

asm   catch   friend    private   public
this    try   new       new       class
inline  protected       throw     virtual

2) Keywords common to C and C++

float   signed    auto    for   sizeof
break   static    case    goto  struct
if      switch    char    int   const
long    continue  default typedef union
do      unsigned  double  else  register
void    enum      return  volatile extern

Tokens in C++ Programming Language



A token is an individual element in a program. More than one taken can appear in a single line separated by white spaces. White space may be blank, carriage return or tab. The possible C++ tokens are

1) keywords
2) identifiers
3) constants
4) operators
5) strings

Manipulators in C++ Programming Language



Manipulators are functions used with the insertion operator (<<). These are used to format the data to be displayed. They are,

1) endl
2) setw

1) endl - end line

This function is used to transfer the control to a new line while printing.

Example:
cout<<"Name :"<<name<<endl<<"Age"<<age;

2) setw - set width

This function is used to set the width of the output list. The list may be variables or constants. The output is right justified.

The general form is

setw(size).

where
size - number of characters to be displayed. This should be an integer.


cout and cin objects in C++ Programming


cout object

cout is an object. It is predefined in the headerfile iostream.h. It is used to display the information on the VDU. The general form is,

cout << list to be printed;

When this statement is executed, the list on the right hand side of the operator << is directed to the object cout and displayed on the VDU.

Rules for cout objects:
1) This should terminate with semicolon (;)
2) If the list to be printed contains more than one, each should be separated by <<.
3) The list to be printed may be variables or constants.

cin object

cin is an object. It is predefined in the header file iostream.h. It is used to give values to the variables through keyboard. The general form is,

cin >> list of variables;

When this statement is executed, the data entered through the keyboard are assigned to the list of variables on the righthand side of the operator >>.

Rules for cin objects:
1) This should terminate with semicolon.
2) The list of variables should be separated by >> operated.

Structure of C++ Programs - For Beginers


Include file

In C++ there are a number of files called header files. These files contain number of predefined functions, classes, variables and data. If we want to use the predefined functions, classes, variables and data in our program, the appropriate header file should be included at the beginning of the program. The general form of include file is

#include<headerfilename.h>

Examples : iostream.h, fstream.h, graphic.h, math.h, process.h, iomanip.h etc.

Class definition

It is an user defined data type having defined member functions and member variables. We can have more than one class in a program.

Main function

In all C++ programs, there is a function named main. Through this function only we can access other parts of the program. This function should return a value.

Variable, object declaration

In this section the required variables and objects are declared.

Body of main fuction

In this section valid C++ statements, message passing etc., are given.

What is Main Difference C++ have from C ?



C++ is an object oriented language. It is an extension of C language. C++ compiler supports both C and C++.

The following important features are added with C to make it C++.

1) Class
2) Inheritance
3) Polymorphism
4) Function overloading
5) Operator overloading
6) Data hiding

Software development using C language supports top down structured approach. But C++ language supports bottom-up and object oriented approach.

Advantages of Object Oriented Programming



1) Resuability
In OOP's, programs, fuctions and modules that are written by a user can be reused by other users without any modification.

2) Code sharing
In OOP's, the programmer can share the codes which are common to more than one class by definng it in the parent classes in hierarchical order.

3) Data hiding
In OOP's, the programmer can hide data and functions in a class from other classes.

4) Reduced complexity of a problem
In OOP's, the given problem is viewed as a collection of different objects. Each object is responsible for a specific task. The problem is solved by interfacing the objects. This technique reduces the complexity of the program design.

5) Prototyping

In OOP's software system can be developed more quickly and easily by using the existing defined components. This technique of development is called prototyping.

6) Message passing technique

This technique reduces the complexity of interfacing objects.

7) Extendability

Object Oriented softwares can be easily extended from small to large.

Powered by Blogger.