Pages

CPP Menu driven program for maintaining EMPLOYEE details

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
class employee
{
      int eid;
      char ename[20];
      char empaddr[30];
      char empdesig[20];
      float sal;
   public:
      void getdata();
      void putdata();
      int return_id()
      {
  return eid;
      }
}s;
ifstream fin;
ofstream fout;
void employee::getdata()
{
   cout<<"\n  Enter Employee ID : ";cin>>eid;
   cout<<"\nEnter Employee Name : ";gets(ename);
   cout<<"\n      Enter Address : ";gets(empaddr);
   cout<<"\n  Enter Designation : ";gets(empdesig);
   cout<<"\n       Enter Salary : ";cin>>sal;
}
void employee::putdata()
{
   cout<<"\n----EMPLOYEE DETAILS----";
   cout<<"\n  Employee ID = "<<eid;
   cout<<"\nEmployee Name = "<<ename;
   cout<<"\n      Address = "<<empaddr;
   cout<<"\n  Deisgnation = "<<empdesig;
   cout<<"\n       Salary = "<<sal;
}
void create()
{
   int n;
   fout.open("record.dat",ios::out|ios::binary);
   cout<<"\nEnter Number of Employees"
       <<"to be Added : ";
   cin>>n;
   for(int i=0;i<n;i++)
   {
      cout<<"\nEnter Details of Employee "<<i+1;
      cout<<"\n-----------------------------";
      s.getdata();
      fout.write((char *)&s,sizeof(s));
      cout<<"\nDetails are Added to File Successfully";
   }
   fout.close();
}
void append()
{
   fout.open("record.dat",ios::app|ios::binary);
   cout<<"\n---Enter the Details to be Appended---";
   s.getdata();
   fout.write((char *)&s,sizeof(s));
   fout.close();
}
void display()
{
   fin.open("record.dat",ios::in|ios::binary);
   while(fin.read((char *)&s,sizeof(employee)))
      if(!fin.eof()) s.putdata();
   fin.close();
}
void modify()
{
   int flag=0;
   fstream f;
   f.open("record.dat",ios::in|ios::out|ios::binary);
   long pos;
   int g;
   employee s;
   cout<<"\nEnter the ID to modify : ";cin>>g;
   while(f)
   {
      pos=f.tellg();
      f.read((char *)&s,sizeof(s));
      if(s.return_id()==g)
      {
  s.getdata();
  flag=1;
  f.seekg(pos);
  f.write((char *)&s,sizeof(s));
      }
   }
   if(flag==0)
   {
      cout<<"\nSorry ID not found";
   }
   f.close();
}
void main()
{
   int c;
   do
   {
      clrscr();
      cout<<"\n----MENU----";
      cout<<"\n1.Create\n2.Display\n3.Append"
   <<"\n4.Modify\n5.Exit";
      cout<<"\nEnter your choice : ";cin>>c;
      switch(c)
      {
  case 1: create();
   break;
  case 2: display();
   break;
  case 3: append();
   cout<<"\nNew Details are added";
   break;
  case 4: modify();
   break;
  case 5: exit(0);
 default: cout<<"\nWrong choice!!!";
       }
       cout<<"\nPress any key to continue";
       getch();
      }while(1);
}


CPP Program for mantaining BOOK Details

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
class book
{
      int bno;
      char bname[30];
      int price;
   public:
   void input()
   {  cout<<"\nEnter Book Number : ";
      cin>>bno;
      cout<<"\nEnter Book Name   : ";
      gets(bname);
      cout<<"\nEnter the Price   : ";
      cin>>price;
   }
   void display()
   {
      cout<<"\nBook Number : "<<bno;
      cout<<"\nBook Name   : "<<bname;
      cout<<"\nBook Price  : Rs"<<price;
   }
   int getbno()
   {
      return bno;
   }
};
void main()
{
   book b;
   int n, i, j, choice;
   fstream file;
   char ch;
   do
   {
      clrscr();
      cout<<"\n----MENU----";
      cout<<"\n1.Enter Details of Book\n2.Display the Details"
   <<"\n3.Search for Book\n4.Exit";
      cout<<"\nEnter your choice : ";
      cin>>choice;
      switch(choice)
      {
  case 1: file.open("bk.dat",ios::out|ios::binary);
   cout<<"\nEnter Number of Records to be Stored : ";
   cin>>n;
   for(i=0;i<n;i++)
   {
       b.input();
       file.write((char *)&b,sizeof(b));
   }
   file.close();
   break;
  case 2: file.open("bk.dat",ios::in|ios::binary);
   cout<<"\nThe Details are ";
   cout<<"\n---------------";
   do
   {
      file.read((char *)&b,sizeof(b));
      if(!file.eof()) b.display();
      cout<<"\n";
   }while(file);
   file.close();
   break;

  case 3: int bn,flag=0;
   cout<<"\nEnter the Book Number to be Searched : ";
   cin>>bn;
   file.open("bk.dat",ios::in|ios::binary);
   while(file)
   {
      file.read((char *)&b,sizeof(b));
      if(bn==b.getbno())
      {
         b.display();
         flag=1;
         break;
      }
   }
   if(flag==0)
      cout<<"\nNo Recors Found";
   file.close();
   break;
  case 4: exit(0);
 default: cout<<"\nWrong choice!!!";
 }
 cout<<"\nPress any key to continue";
 getch();
       }while(1);
}

Maintaining STUDENT records in a file - C++ Program

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
class student
{
   char name[30];
   int rollno;
   int marks;
   public:
    void input()
    {
       cout<<"\nEnter Name   : ";
       gets(name);
       cout<<"\nEnter Rollno : ";
       cin>>rollno;
       cout<<"\n Enter Marks : ";
       cin>>marks;
    }
    void display()
    {
       cout<<"\n"<<name<<"\t"<<rollno<<"\t"<<marks;
       if(marks>=96)
  cout<<"\tComputer SC";
       else if(marks>=91&&marks<90)
  cout<<"\tElectronics";
       else if(marks>=86&&marks<=90)
  cout<<"\tMechanical";
       else if(marks>=81&&marks<=85)
  cout<<"\tElectrical";
       else if(marks>=76&&marks<=80)
  cout<<"\tChemical";
       else if(marks>=71&&marks<=75)
  cout<<"\tCivil";
       else
  cout<<"\tNone";
    }
};
    void main()
    {
       clrscr();
       student s;
       int i, j, n, ch;
       fstream ofile, afile;
       char ch1;
       do
       {
   clrscr();
   cout<<"\n----MENU----";
   cout<<"\n1.Add Record\n2.Show Record"
       <<"\n3.Exit";
   cout<<"\nEnter your choice : ";
   cin>>ch;
   switch(ch)
   {
      case 1: ofile.open("ST.dat",ios::app|ios::binary);
       cout<<"\nEnter number of records to be entered : ";
       cin>>n;
       for(i=0;i<n;i++)
       {
          s.input();
          ofile.write((char *)&s,sizeof (s));
       }
       ofile.close();
       break;
      case 2: cout<<"\nName\tRollno\tMarks\tStream";
       afile.open("ST.dat",ios::in|ios::binary);
       while(afile)
       {
          afile.read((char *)&s,sizeof (s));
          if(!afile)
          break;
          s.display();
       }
       afile.close();
       break;
      case 3: exit(0);
     default: cout<<"\nWrong choice!!!";
    }
    cout<<"\nPress any key to cotinue";
    getch();
   }while(1);
        }

Menu driven C++ program for writing, reading a file and writing vowels in another file

#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
void main()
{
   clrscr();
   int n,choice, flag;
   fstream file1,file2;
   char str[256];
   char ch;
   do
   {
      clrscr();
      cout<<"\n---MENU---\n1.Write text to the first file"
   <<"\n2.Read text from first file\n3.Write vowels to the second file"
   <<"\n4.Display the second file\n5.Exit";
      cout<<"\nEnter your choice : ";
      cin>>choice;
      switch(choice)
      {
  case 1: file1.open("smp1.txt",ios::out);
   cout<<"\nEnter the text : ";
   gets(str);
   file1<<str;
   file1.close();
   cout<<"\nFile1 Created successfully";
   break;
  case 2: file1.open("smp1.txt",ios::in);
   while(file1)
   {
      file1.get(ch);
      cout<<ch;
   }
   file1.close();
   break;
  case 3: file1.open("smp1.txt",ios::in);
   file2.open("smp2.txt",ios::out);
   while(file1.eof()==0)
   {
      file1.get(ch);
      if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
         file2.put(ch);
   }
   file1.close();
   file2.close();
   cout<<"\nFile 2 is created with vowels from File 1";
   break;
  case 4: file2.open("smp2.txt",ios::in);
   cout<<"\nLower case vowels : ";
   flag=0;
   while(file2)
   {
      file2.get(ch);
      if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
      {
         cout<<ch;
         flag=1;
      }
   }
   if(flag==0)
      cout<<"\nNo lower case vowels";
   cout<<"\nUpper case vowels : ";
   flag=0;
   file2.close();
   file2.open("smp2.txt",ios::in);
   while(file2)
   {
      file2.get(ch);
      if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
         {
     cout<<ch;
     flag=1;
         }
   }
   if(flag==0)
      cout<<"\nNo upper case vowels";
   break;
  case 5: exit(0);
 default: cout<<"\nWrong choice!!!";
   break;
      }
      cout<<"\nPress any key to continue";
      getch();
     } while(1);
    }


Program for printing the Upper and Lower triangular matrices of a square matrix (for Plus2 Students)

#include<iostream.h>
#include<conio.h>
#include<process.h>
void l_triangle(int a[30][30], int n)
{
   int i=0, j=0;
   for(i=0;i<n;i++)
   {
     for(j=0;j<n;j++)
     {
       if(i>=j)
	 cout<<a[i][j]<<" ";
       else
       cout<<" ";
     }
     cout<<"\n";
   }
}
void u_triangle(int a[30][30], int n)
{
   int i=0, j=0;
   for(i=0;i<n;i++)
   {
     for(j=0;j<n;j++)
     {
       if(i<=j)
	 cout<<a[i][j]<<" ";
       else
	 cout<<" ";
     }
     cout<<"\n";
   }
}
void main()
{
   clrscr();
   int i, j, a[30][30], r, c; char ch;
   do
   {
     cout<<"\n\nMENU\n\n";
     cout<<"1. Enter elements\n2. Display matrix"
	 <<"\n3. Display upper triangle\n4. Display lower triangle"
	 <<"\n5. Exit";
     cout<<"\nEnter your choice ";
     cin>>c;
     switch(c)
     {
       case 1: cout<<"\nEnter row and column(square matrix only)";
	       cin>>r>>c;
	       cout<<"\nEnter the elements";
	       for(i=0;i<r;i++)
		 {for(j=0;j<c;j++)
		   cin>>a[i][j];
		 }
	       break;
       case 2: cout<<"\nMatrix is";
	       for(i=0;i<r;i++)
	       {
		 cout<<"\n";
		 for(j=0;j<r;j++)
		 cout<<a[i][j]<<" ";
	       }
	       break;
       case 3: cout<<"\nUpper triangle matrix\n";
	       u_triangle(a,r);
	       break;
       case 4: cout<<"\nLower triangle matrix\n";
	       l_triangle(a,r);
	       break;
       case 5: cout<<"\nExit";
	       exit(0);
      default: cout<<"\nWrong choice";
     }
   cout<<"\nDo you want to continue";
   cin>>ch;
   }while( ch=='Y'|| ch=='y');
   getch();
}

HOW TO COMPILE AND RUN A C++ PROGRAM in UBUNTU
----------------------------------------------

1. Type in source code in gedit

2. Save as filename.cpp
   (note that once you save as .cpp gedit will begin to show 
   source code relevent colors whenever the file is opened in gedit)

3. Open terminal (command line) and cd (change directory) over to 
   the directory where you saved the file.

4. At the prompt type: "g++ filename.cpp".

5. You may see a load of warnings and recommendations, but if the 
   code has no errors then an executable will still be created.

6. Type "ls" on the command line to see the program titled "a.out" 
   in the current directory.

7. If it's there (and wasn't before) that is your compiled file.

8. type "./a.out" to run it!


Zone wise Sale of Products details.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. ZONE-SALES.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  SALES.
           02 PRODUCT OCCURS 4 TIMES.
              03  ZONE  PIC 9999 OCCURS 5 TIMES.
       77  I         PIC 9.
       77  J         PIC 9.
       77  BP        PIC 9999.
       77  BZ        PIC Z.
       01  DISP-HEAD PIC X(20) VALUE "  Z1  Z2  Z3  Z4 TOT".
       01  UL        PIC X(20) VALUE ALL "-".
       01  DISP-REC.
           02 E-Z1   PIC ZZZ9.
           02 E-Z2   PIC ZZZ9.
           02 E-Z3   PIC ZZZ9.
           02 E-Z4   PIC ZZZ9.
           02 E-Z5   PIC ZZZ9.

       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM READ-DATA VARYING I FROM 1 BY 1 UNTIL I > 3
                   AFTER J FROM 1 BY 1 UNTIL J > 4.
           PERFORM SUM-PARA1 VARYING I FROM 1 BY 1 UNTIL I > 4.
           PERFORM SUM-PARA3 VARYING I FROM 1 BY 1 UNTIL I > 3.
           DISPLAY DISP-HEAD.
           DISPLAY UL.
           PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > 4.
           DISPLAY UL.
           PERFORM COM-PARA1 VARYING I FROM 1 BY 1 UNTIL I > 3.
           DISPLAY " ".
           STOP RUN.
       READ-DATA.
           DISPLAY "Enter Quantity of Product : " I " of Zone : " J.
           ACCEPT ZONE(I, J).
       SUM-PARA1.
           MOVE 0 TO ZONE(4, I).
           PERFORM SUM-PARA2 VARYING J FROM 1 BY 1 UNTIL J > 3.
       SUM-PARA2.
           COMPUTE ZONE(4, I) = ZONE(4, I) + ZONE(J, I).
       SUM-PARA3.
           MOVE 0 TO ZONE(I, 5).
           PERFORM SUM-PARA4 VARYING J FROM 1 BY 1 UNTIL J > 4.
       SUM-PARA4.
           COMPUTE ZONE(I, 5) = ZONE(I, 5) + ZONE(I, J).
       DISP-PARA.
           MOVE ZONE(I, 1) TO E-Z1.
           MOVE ZONE(I, 2) TO E-Z2.
           MOVE ZONE(I, 3) TO E-Z3.
           MOVE ZONE(I, 4) TO E-Z4.
           MOVE ZONE(I, 5) TO E-Z5.
           DISPLAY DISP-REC.
       COM-PARA1.
           MOVE 0 TO BP.
           MOVE 0 TO BZ.
           PERFORM COM-PARA2 VARYING J FROM 1 BY 1 UNTIL J > 4.
           DISPLAY "Product : " I " Sold More in Zone : " BZ.
       COM-PARA2.
           IF ZONE(I, J) > BP
              MOVE ZONE(I, J) TO BP
              MOVE J TO BZ.

Sorting Sample Program using COBOL


      *
      *   A student record have the following structure:
      *
      *   Register Number,
      *   Name of the Student,
      *   Course and
      *   Year of Admin.
      *
      *   Write a COBOL program to read details of a set of students
      *   through the keyboard and stored in a sequential file and
      *   generate a list of students joined for various courses in
      *   different year in a suitable order using SORT verb of COBOL.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SORTING.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
           SELECT SORT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO    PIC 9(3).
           02 NAME     PIC X(30).
           02 COURSE   PIC X(10).
           02 YOA      PIC 9(4).
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 W-REGNO  PIC 9(3).
           02 W-NAME   PIC X(30).
           02 W-COURSE PIC X(10).
           02 W-YOA    PIC 9(4).
       FD  SORT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "SORT.DAT"
           DATA RECORD IS SORT-REC.
       01  SORT-REC.
           02 S-REGNO  PIC 9(3).
           02 S-NAME   PIC X(30).
           02 S-COURSE PIC X(10).
           02 S-YOA    PIC 9(4).
       WORKING-STORAGE SECTION.
       01  SHOW-REC.
           02 S-REGNO  PIC 9(3).
           02 FILLER   PIC X(3).
           02 S-NAME   PIC X(30).
           02 FILLER   PIC X(3).
           02 S-COURSE PIC X(10).
           02 FILLER   PIC X(3).
           02 S-YOA    PIC 9(4).
       77  FLAG        PIC X.
       77  UL          PIC X(56) VALUE ALL "-".
       77  DL          PIC X(56) VALUE ALL "=".
       PROCEDURE DIVISION.
       MAIN-PARA.
           OPEN OUTPUT STU-FILE.
       DATA-GET.
           DISPLAY (01 01) ERASE.
           DISPLAY "-------------------------------".
           DISPLAY "        DATA INPUT FORM".
           DISPLAY "-------------------------------".
           DISPLAY "Enter Reg.No : ".
           ACCEPT REGNO.
           DISPLAY "  Enter Name : ".
           ACCEPT NAME.
           DISPLAY "Enter Course : ".
           ACCEPT COURSE.
           DISPLAY "   Enter YOA : ".
           ACCEPT YOA.
           WRITE STU-REC.
           DISPLAY "-------------------------------".
           DISPLAY "Press Y/y to Continue...".
           ACCEPT FLAG.
           IF FLAG = "Y" OR FLAG = "y" GO TO DATA-GET.
       CLOSE-PARA.
           CLOSE STU-FILE.
       SORT-PARA.
           SORT WORK-FILE ON ASCENDING KEY W-YOA, W-COURSE, W-REGNO
           USING STU-FILE
           GIVING SORT-FILE.
       OPEN-UNSORT.
           OPEN INPUT STU-FILE.
           DISPLAY (01 01) ERASE.
           DISPLAY UL.
           DISPLAY "                     UNSORTED DATA".
           DISPLAY DL.
       READ-UNSORT.
           READ STU-FILE RECORD AT END GO TO CLOSE-UNSORT.
           DISPLAY STU-REC.
           GO TO READ-UNSORT.
       CLOSE-UNSORT.
           OPEN INPUT SORT-FILE.
           DISPLAY UL.
           DISPLAY "                  DATA IN SORTED FORM".
           DISPLAY UL.
           DISPLAY "REG   NAME                             COURSE
      -    "YEAR".
           DISPLAY DL.
       READ-SORT.
           READ SORT-FILE RECORD AT END GO TO CLOSE-SORT.
           MOVE CORRESPONDING SORT-REC TO SHOW-REC.
           DISPLAY SHOW-REC.
           GO TO READ-SORT.
       CLOSE-SORT.
           DISPLAY DL.
           DISPLAY " ".
           CLOSE SORT-FILE.
           STOP RUN.

Write a COBOL program to MULTIPLY TWO MATRICES.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIX-MULTIPLICATION.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  MATRIXA.
           02 MATA OCCURS 10 TIMES.
              03 A PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXB.
           02 MATB OCCURS 10 TIMES.
              03 B PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXC.
           02 MATC OCCURS 10 TIMES.
              03 C PIC S9(3) OCCURS 10 TIMES.
       01  E-VAL   PIC -ZZ9.
       01  I       PIC 99.
       01  J       PIC 99.
       01  K       PIC 99.
       01  RW      PIC 99.
       01  RC      PIC 99.
       01  CL      PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY (01 01) ERASE.
           DISPLAY (02 10) "Enter the Order of the Matices".
           DISPLAY (03 10) " I-Matirx : Rows : ".
           DISPLAY (03 31) "Columns : ".
           ACCEPT (03 28) RW.
           ACCEPT (03 41) RC.
           DISPLAY (04 10) "II-Matirx : Rows : ".
           DISPLAY (04 31) "Columns : ".
           DISPLAY (04 28) RC.
           ACCEPT (04 41) CL.
           
           DISPLAY (06 10) "Enter the elements of:".
           DISPLAY (07 10) "First Matrix ".
           DISPLAY (07 50) "Second Matrix".
           MOVE 09 TO LIN.
           MOVE 10 TO COL.
           PERFORM READ-A1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           MOVE 08 TO LIN.
           MOVE 50 TO COL.
           PERFORM READ-B1 VARYING I FROM 1 BY 1 UNTIL I > RC.
           PERFORM COMPUTE-PARA VARYING I FROM 1 BY 1 UNTIL I > RW
                   AFTER J FROM 1 BY 1 UNTIL J > CL.
           ADD 2 TO LIN.
           MOVE 10 TO COL.
           DISPLAY (LIN, 10) "Multiplication of the Matrices".
           DISPLAY (LIN + 1, 10) "------------------------------".
           ADD 2 TO LIN.
           PERFORM DISP-C1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           DISPLAY (LIN, 10) "==============================".
           STOP RUN.
       READ-A1.
           PERFORM READ-A VARYING J FROM 1 BY 1 UNTIL J > RC.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       READ-A.
           ACCEPT (LIN, COL) A(I J).
           ADD 5 TO COL.
       READ-B1.
           PERFORM READ-B VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 50 TO COL.
       READ-B.
           ACCEPT (LIN, COL) B(I J).
           ADD 5 TO COL.
       COMPUTE-PARA.
           MOVE 0 TO C(I J).
           PERFORM MULTI-PARA VARYING K FROM 1 BY 1 UNTIL K > RC.
       MULTI-PARA.
           COMPUTE C(I J) = C(I J) + A(I K) * B(K J).           
       DISP-C1.
           PERFORM DISP-C VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       DISP-C.
           MOVE C(I J) TO E-VAL.
           DISPLAY (LIN, COL) E-VAL.
           ADD 5 TO COL.

Write a COBOL program to ADD TWO MATRICES.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIX-ADDITION.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  MATRIXA.
           02 MATA OCCURS 10 TIMES.
              03 A PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXB.
           02 MATB OCCURS 10 TIMES.
              03 B PIC S9(3) OCCURS 10 TIMES.
       01  MATRIXC.
           02 MATC OCCURS 10 TIMES.
              03 C PIC S9(3) OCCURS 10 TIMES.
       01  E-VAL   PIC -ZZ9.
       01  I       PIC 99.
       01  J       PIC 99.
       01  RW      PIC 99.
       01  CL      PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY (01 01) ERASE.
           DISPLAY (02 10) "Enter the Order of the Matices".
           DISPLAY (03 10) "Rows : ".
           DISPLAY (03 20) "Columns : ".
           ACCEPT (03 17) RW.
           ACCEPT (03 30) CL.
           DISPLAY (05 10) "Enter the elements of:".
           DISPLAY (06 10) "First Matrix ".
           DISPLAY (06 50) "Second Matrix".
           MOVE 08 TO LIN.
           MOVE 10 TO COL.
           PERFORM READ-A1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           MOVE 08 TO LIN.
           MOVE 50 TO COL.
           PERFORM READ-B1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           PERFORM COMPUTE-PARA VARYING I FROM 1 BY 1 UNTIL I > RW
                   AFTER J FROM 1 BY 1 UNTIL J > CL.
           ADD 2 TO LIN.
           MOVE 10 TO COL.
           DISPLAY (LIN, 10) "Sum of the Matrices".
           DISPLAY (LIN + 1, 10) "-------------------".
           ADD 2 TO LIN.
           PERFORM DISP-C1 VARYING I FROM 1 BY 1 UNTIL I > RW.
           DISPLAY (LIN, 10) "===================".
           STOP RUN.
       READ-A1.
           PERFORM READ-A VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       READ-A.
           ACCEPT (LIN, COL) A(I J).
           ADD 5 TO COL.
       READ-B1.
           PERFORM READ-B VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 50 TO COL.
       READ-B.
           ACCEPT (LIN, COL) B(I J).
           ADD 5 TO COL.
       COMPUTE-PARA.
           COMPUTE C(I J) = A(I J) + B(I J).
       DISP-C1.
           PERFORM DISP-C VARYING J FROM 1 BY 1 UNTIL J > CL.
           ADD 1 TO LIN.
           MOVE 10 TO COL.
       DISP-C.
           MOVE C(I J) TO E-VAL.
           DISPLAY (LIN, COL) E-VAL.
           ADD 5 TO COL.

A sequential file contains records of consumers of a Telecom Services having the following structure: Consumer Number, Consumer Name, Name of Exchange, Previous Meter Reading and Current Meter Reading(Give appropriate picture clauses). Write a COBOL program to print Telephone Bill for each consumer in a neat format


      *
      *   A sequential file contains records of consumers of a
      *   Telecom Services having the following structure:
      *   Consumer Number,
      *   Consumer Name,
      *   Name of Exchange,
      *   Previous Meter Reading and
      *   Current Meter Reading (Give appropriate picture clauses).
      *
      *   Write a COBOL program to print Telephone Bill
      *   for each consumer in a neat format according to the
      *   following slab:
      *
      *   Slab   Consumption   Rate/Unit(in Rs.)   Telehpone Rent
      *
      *    I      First 250        @ 0.80             Rs. 250
      *    II     Next 600         @ 1.00             Rs. 300
      *    III    Balance          @ 1.20             Rs. 500
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. TELE-BILL.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT TELE-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  TELE-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "TELE.DAT"
           DATA RECORD IS TELE-REC.
       01  TELE-REC.
           02 CNO      PIC 9(4).
           02 NAME     PIC X(20).
           02 EXC      PIC X(15).
           02 PRE-READ PIC 9(6).
           02 CUR-READ PIC 9(6).
       WORKING-STORAGE SECTION.
       01  CONSUM      PIC 9(6).
       01  E-CONSUM    PIC Z(5)9.
       01  E-CNO       PIC ZZ9.
       01  E-PRE-READ  PIC Z(5)9.
       01  E-CUR-READ  PIC Z(5)9.
       01  RENT        PIC 9(5).
       01  E-RENT      PIC Z(4)9.
       01  CALL-CHARGE PIC 9(5)V99.
       01  E-CC        PIC Z(4)9.99.
       01  BILL-AMT    PIC Z(5).99.
       01  PAUSE       PIC X.
       PROCEDURE DIVISION.
       OPEN-PARA.
           OPEN INPUT TELE-FILE.
       PROCESS-PARA.
           DISPLAY (01 01) ERASE.
           READ TELE-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE CONSUM = CUR-READ - PRE-READ.
           IF CONSUM > 850
              MOVE 500 TO RENT
              COMPUTE CALL-CHARGE = 800 + (CONSUM - 850) * 1.20
           ELSE
              IF CONSUM > 250
                 MOVE 300 TO RENT
                 COMPUTE CALL-CHARGE = 200 + (CONSUM - 250) * 1.00
              ELSE
                 MOVE 250 TO RENT
                 COMPUTE CALL-CHARGE = CONSUM * 0.80.
           MOVE CALL-CHARGE TO E-CC.
           COMPUTE BILL-AMT = RENT + CALL-CHARGE.
           PERFORM DISPLAY-PARA.
           ACCEPT PAUSE.
           GO TO PROCESS-PARA.
       CLOSE-PARA.
           CLOSE TELE-FILE.
           STOP RUN.
       DISPLAY-PARA.
           MOVE CNO TO E-CNO.
           MOVE PRE-READ TO E-PRE-READ.
           MOVE CUR-READ TO E-CUR-READ.
           MOVE CONSUM TO E-CONSUM.
           MOVE RENT TO E-RENT.
           DISPLAY "-----------------------------------------------".
           DISPLAY "               Telephone Bill ".
           DISPLAY "-----------------------------------------------".
           DISPLAY "          Consumer No : " E-CNO.
           DISPLAY "                 Name : " NAME.
           DISPLAY "        Exchange Name : " EXC.
           DISPLAY " ".
           DISPLAY "     ------------------------------------".
           DISPLAY "      Current Reading : " E-CUR-READ.
           DISPLAY "     Previous Reading : " E-PRE-READ.
           DISPLAY "     ------------------------------------".
           DISPLAY "          Consumption : " E-CONSUM.
           DISPLAY " ".
           DISPLAY "                 Rent : Rs. " E-RENT.
           DISPLAY "         Call Charges : Rs. " E-CC.
           DISPLAY "     ------------------------------------".
           DISPLAY "          Bill Amount : Rs. " BILL-AMT.
           DISPLAY "===============================================".


A student file contain the marks of students scored in various subjects in a class. Each record contain Register Number, Name of Student and Marks scored for Subject1, Subject2 and Subject3(maximum marks 100). Write a COBOL program to prepare a Rank List.


      *
      *   A student file contain the marks of students scored
      *   in various subjects in a class. Each record contain
      *   Register Number, Name of Student and Marks scored for
      *   Subject1, Subject2 and Subject3(maximum marks 100).
      *
      *   Write a COBOL program to prepare a Rank List.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. RANKING.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT TOT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
           SELECT RANK-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "MARK.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
       FD  TOT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "TOTAL.DAT"
           DATA RECORD IS TOT-REC.
       01  TOT-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
           02 TOTAL PIC 9(3).
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
           02 TOTAL PIC 9(3).
       FD  RANK-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "RANK.DAT"
           DATA RECORD IS RANK-REC.
       01  RANK-REC.
           02 REGNO   PIC 9(3).
           02 NAME    PIC X(20).
           02 M1      PIC 9(3).
           02 M2      PIC 9(3).
           02 M3      PIC 9(3).
           02 TOTAL   PIC 9(3).
           02 RANK    PIC 9(3).
       WORKING-STORAGE SECTION.
       01  PRE-TOTAL  PIC 9(3) VALUE 0.
       01  T-RANK     PIC 9(3) VALUE 0.
       01  SHOW-REC.
           02 REGNO   PIC ZZ9.
           02 FILLER  PIC X(2).
           02 NAME    PIC X(20).
           02 FILLER  PIC X(2).
           02 M1      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 M2      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 M3      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 TOTAL   PIC ZZ9.
           02 FILLER  PIC X(2).
           02 RANK    PIC ZZ9.
       PROCEDURE DIVISION.
       TOT-PARA.
           OPEN INPUT STU-FILE
                OUTPUT TOT-FILE.
       READMARK-PARA.
           READ STU-FILE RECORD INTO TOT-REC
                AT END GO TO CLOSE-STU-PARA.
           COMPUTE TOTAL OF TOT-REC = M1 OF TOT-REC +
                                      M2 OF TOT-REC +
                                      M3 OF TOT-REC.
           WRITE TOT-REC.
           GO TO READMARK-PARA.
       CLOSE-STU-PARA.
           CLOSE STU-FILE TOT-FILE.
       SORT-PARA.
           SORT WORK-FILE ON DESCENDING KEY TOTAL OF WORK-REC
           USING TOT-FILE
           GIVING RANK-FILE.
       OPEN-PARA.
           OPEN I-O RANK-FILE.
       READ-PARA.
           READ RANK-FILE RECORD AT END GO TO CLOSE-PARA.
           IF PRE-TOTAL NOT = TOTAL OF RANK-REC
              COMPUTE T-RANK = T-RANK + 1
              MOVE TOTAL OF RANK-REC TO PRE-TOTAL.
           MOVE T-RANK TO RANK OF RANK-REC.
           REWRITE RANK-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           CLOSE RANK-FILE.
           OPEN INPUT RANK-FILE.
           DISPLAY "--------------------------------------------------".
           DISPLAY "                   RANK LIST".
           DISPLAY "--------------------------------------------------".
           DISPLAY "REG  NAME                   M1   M2   M3  TOT RANK".
           DISPLAY "==================================================".
       READRANK-PARA.
           READ RANK-FILE RECORD AT END GO TO CLOSE-RANK-PARA.
           MOVE CORRESPONDING RANK-REC TO SHOW-REC.
           DISPLAY SHOW-REC.
           GO TO READRANK-PARA.
       CLOSE-RANK-PARA.
           CLOSE RANK-FILE.
           DISPLAY "==================================================".
           DISPLAY " ".
           STOP RUN.

A sequential file contains records of consumers of an electricity board having the following structure: Consumer Number, Name of Consumer, Previous Meter Reading and Current Meter Reading(give appropriate picture clauses). Write a COBOL program to print the Electricity Bill for each consumer in a neat format .


      *
      *   A sequential file contains records of consumers of an
      *   electricity board having the following structure:
      *   Consumer Number,
      *   Name of Consumer,
      *   Previous Meter Reading and
      *   Current Meter Reading (give appropriate picture clauses).
      *
      *   Write a COBOL program to print the Electricity Bill
      *   for each consumer in a neat format according to the
      *   following slab:
      *
      *       Consumption     Rate/Unit(in Rs.)
      *           < 50             @ 1.00
      *         50 - 100           @ 1.25
      *           > 100            @ 1.50
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ELECTRICITY-BILL.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT ELE-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  ELE-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "ELE.DAT"
           DATA RECORD IS ELE-REC.
       01  ELE-REC.
           02 CNO      PIC 9(4).
           02 NAME     PIC X(20).
           02 PRE-READ PIC 9(6).
           02 CUR-READ PIC 9(6).
       WORKING-STORAGE SECTION.
       01  CONSUM      PIC 9(4).
       01  E-CONSUM    PIC Z(3)9.
       01  E-CNO       PIC Z(3)9.
       01  E-PRE-READ  PIC Z(5)9.
       01  E-CUR-READ  PIC Z(5)9.
       01  BILL-AMT    PIC Z(5).99.
       01  PAUSE       PIC X.
       PROCEDURE DIVISION.
       OPEN-PARA.
           OPEN INPUT ELE-FILE.
       PROCESS-PARA.
           DISPLAY (01 01) ERASE.
           READ ELE-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE CONSUM = CUR-READ - PRE-READ.
           IF CONSUM > 100
              COMPUTE BILL-AMT = CONSUM * 1.50
           ELSE
              IF CONSUM > 50
                 COMPUTE BILL-AMT = CONSUM * 1.25
              ELSE
                 COMPUTE BILL-AMT = CONSUM * 1.00.
           PERFORM DISPLAY-PARA.
           ACCEPT PAUSE.
           GO TO PROCESS-PARA.
       CLOSE-PARA.
           CLOSE ELE-FILE.
           STOP RUN.
       DISPLAY-PARA.
           MOVE CNO TO E-CNO.
           MOVE PRE-READ TO E-PRE-READ.
           MOVE CUR-READ TO E-CUR-READ.
           MOVE CONSUM TO E-CONSUM.
           DISPLAY "-----------------------------------------------".
           DISPLAY "               Electricity Bill ".
           DISPLAY "-----------------------------------------------".
           DISPLAY "          Consumer No.: " E-CNO.
           DISPLAY "                 Name : " NAME.
           DISPLAY " ".
           DISPLAY "     ----------------------------------".
           DISPLAY "      Current Reading : " E-CUR-READ.
           DISPLAY "     Previous Reading : " E-PRE-READ.
           DISPLAY " ".
           DISPLAY "          Consumption : " E-CONSUM.
           DISPLAY "     ----------------------------------".
           DISPLAY "          Bill Amount : " BILL-AMT.
           DISPLAY "===============================================".


An employee record contains Badge Number/Employee Number, Name of Employee, Basic Pay, DA, HRA and Deductions. Write a COBOL program to accept details of a set of employees through keyboard and stored in a sequential file and print the contents of the file in a neat format.


      *
      *   An employee record contains Badge Number/Employee Number,
      *   Name of Employee, Basic Pay, DA, HRA and Deductions.
      *
      *   Write a COBOL program to accept details of a set of
      *   employees through keyboard and stored in a sequential file
      *   and print the contents of the file in a neat format.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. CREATING-EMPLOYEE-SEQ-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT EMP-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  EMP-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "EMP.DAT"
           DATA RECORD IS EMP-REC.
       01  EMP-REC.
           02 BADNO      PIC 9(3).
           02 NAME       PIC X(20).
           02 BASIC-PAY  PIC 9(5)V99.
           02 DA         PIC 9(5)V99.
           02 HRA        PIC 9(5)V99.
           02 DEDUCTION  PIC 9(5)V99.
       WORKING-STORAGE SECTION.
       01  E-EMP-REC.
           02 FILLER     PIC XX.
           02 BADNO      PIC ZZ9.
           02 FILLER     PIC XXX.
           02 NAME       PIC X(20).
           02 FILLER     PIC XX.
           02 BASIC-PAY  PIC Z(4)9.99.
           02 FILLER     PIC XXX.
           02 DA         PIC Z(4)9.99.
           02 FILLER     PIC XXX.
           02 HRA        PIC Z(4)9.99.
           02 FILLER     PIC XXX.
           02 DEDUCTION  PIC Z(4)9.99.
       01  OPTION       PIC X VALUE IS "Y".
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
           PERFORM WRITE-PARA UNTIL OPTION NOT = "Y".
           PERFORM SECOND-OPEN-PARA.
           PERFORM READ-PARA.
       OPEN-PARA.
           OPEN OUTPUT EMP-FILE.
       WRITE-PARA.
           DISPLAY (01 01) ERASE.
           DISPLAY (02 10) "Enter the following details of an Employee".
           DISPLAY (03 10) "------------------------------------------".
           DISPLAY (04 10) "  Badge/Emp. No.: ".
           ACCEPT (04 28) BADNO OF EMP-REC.
           DISPLAY (05 10) "Name of Employee: ".
           ACCEPT (05 28) NAME OF EMP-REC.
           DISPLAY (06 10) "      Basic Pay : ".
           ACCEPT (06 28) BASIC-PAY OF EMP-REC.
           DISPLAY (07 10) "             DA : ".
           ACCEPT (07 28) DA OF EMP-REC.
           DISPLAY (08 10) "            HRA : ".
           ACCEPT (08 28) HRA OF EMP-REC.
           DISPLAY (09 10) "      Deduction : ".
           ACCEPT (09 28) DEDUCTION OF EMP-REC.
           WRITE EMP-REC.
           DISPLAY (12 10) "Press Y/y to add more Employee : ".
           ACCEPT (12 44) OPTION.
           IF OPTION = "y"
              MOVE "Y" TO OPTION.
       SECOND-OPEN-PARA.
           CLOSE EMP-FILE.
           OPEN INPUT EMP-FILE.
           DISPLAY (01 01) ERASE.
           DISPLAY "----------------------------------------------------
      -    "-------------------".
           DISPLAY "Emp.No. Name of Employee     Basic Pay       D.A.
      -    "  H.R.A.  Deduction".
           DISPLAY "----------------------------------------------------
      -    "-------------------".
       READ-PARA.
           READ EMP-FILE RECORD AT END GO TO CLOSE-PARA.
           MOVE CORRESPONDING EMP-REC TO E-EMP-REC.
           DISPLAY E-EMP-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           DISPLAY "====================================================
      -    "===================".
           CLOSE EMP-FILE.
           STOP RUN.

Sample MERGE program using COBOL


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MERGING-OF-SEQUENTIAL-FILES.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU1-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT STU2-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT OUT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
       DATA DIVISION.
       FILE SECTION.
       FD  STU1-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LIST1.DAT"
           DATA RECORD IS STU1-REC.
       01  STU1-REC.
           02 REGNO1   PIC 999.
           02 NAME1    PIC X(10).
           02 YOA1     PIC 9999.
       FD  STU2-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LIST2.DAT"
           DATA RECORD IS STU2-REC.
       01  STU2-REC.
           02 REGNO2   PIC 999.
           02 NAME2    PIC X(10).
           02 YOA2     PIC 9999.
       FD  OUT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "MLIST.DAT"
           DATA RECORD IS OUT-REC.
       01  OUT-REC.
           02 OREGNO   PIC 999.
           02 ONAME    PIC X(10).
           02 OYOA     PIC 9999.
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 WREGNO   PIC 999.
           02 WNAME    PIC X(10).
           02 WYOA     PIC 9999.
       PROCEDURE DIVISION.
       MAIN-PARA.
           MERGE WORK-FILE
                ON DESCENDING KEY WYOA
                ON ASCENDING KEY WNAME
                USING STU1-FILE STU2-FILE
                GIVING OUT-FILE.
       OPEN-PARA.
           OPEN INPUT OUT-FILE.
           DISPLAY "------------------------------------".
           DISPLAY "   MERGED RECORDS".
           DISPLAY "------------------------------------".
       READ-PARA.
           READ OUT-FILE RECORD AT END GO TO CLOSE-PARA.
           DISPLAY OUT-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           DISPLAY "------------------------------------".
           DISPLAY " ".
           CLOSE OUT-FILE.
           STOP RUN.

Sample Sorting program using COBOL


       IDENTIFICATION DIVISION.
       PROGRAM-ID. SORTING-OF-SEQUENTIAL-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT OUT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "NAMELIST.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(10).
           02 YOA     PIC 9999.
       FD  OUT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "SORTLIST.DAT"
           DATA RECORD IS OUT-REC.
       01  OUT-REC.
           02 OREGNO   PIC 999.
           02 ONAME    PIC X(10).
           02 OYOA     PIC 9999.
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 WREGNO   PIC 999.
           02 WNAME    PIC X(10).
           02 WYOA     PIC 9999.
       PROCEDURE DIVISION.
       MAIN-PARA.
           SORT WORK-FILE
                ON DESCENDING KEY WYOA
                ON ASCENDING KEY WNAME
                USING STU-FILE
                GIVING OUT-FILE.
           STOP RUN.

Preparation of Mark List by reading data from a Student File (Line Sequential)


       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUDENT-FILE-MARKLIST-PREPARATION.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(30).
           02 M1      PIC 999.
           02 M2      PIC 999.
           02 M3      PIC 999.
       WORKING-STORAGE SECTION.
       01  TM         PIC 999.
       01  EDT-REC.
           02 EREGNO  PIC ZZ9.
           02 ENAME   PIC X(30).
           02 EM1     PIC ZZ9.
           02 EM2     PIC ZZ9.
           02 EM3     PIC ZZ9.
           02 ETM     PIC ZZ9.
           02 RESULT  PIC X(20).
       01  SL         PIC X(40) VALUE ALL "-".
       01  DL         PIC X(40) VALUE ALL "=".
       01  PAUSE      PIC X.
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
       READ-PARA.
           READ STU-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE TM = M1 + M2 + M3.
           IF TM NOT < 240
              MOVE "Distinction" TO RESULT
           ELSE IF TM NOT < 180
                   MOVE "First Class" TO RESULT
                ELSE IF TM NOT < 150
                        MOVE "Second Class" TO RESULT
                     ELSE
                        MOVE "Failed" TO RESULT.
           MOVE REGNO TO EREGNO.
           MOVE NAME TO ENAME.
           MOVE M1 TO EM1.
           MOVE M2 TO EM2.
           MOVE M3 TO EM3.
           MOVE TM TO ETM.
           DISPLAY (01 01) SPACES.
           DISPLAY (02 01) SL.
           DISPLAY (03 12) "M A R K   L I S T".
           DISPLAY (04 01) DL.
           DISPLAY (05 01) "   Register No : " EREGNO.
           DISPLAY (06 01) "          Name : " ENAME.
           DISPLAY (07 01) "      Marks in  ".
           DISPLAY (08 01) "     Subject-1 : " EM1.
           DISPLAY (09 01) "     Subject-2 : " EM2.
           DISPLAY (10 01) "     Subject-3 : " EM3.
           DISPLAY (12 01) "   Total Marks : " ETM.
           DISPLAY (14 01) "        Result : " RESULT.
           DISPLAY (16 01) DL.
           ACCEPT PAUSE.
           GO TO READ-PARA.
       OPEN-PARA.
           OPEN INPUT STU-FILE.
       CLOSE-PARA.
           DISPLAY " ".
           CLOSE STU-FILE.
           STOP RUN.

Reading a Line Sequential File and displaying the content in a neat format


       IDENTIFICATION DIVISION.
       PROGRAM-ID. READING-LINE-SEQUENTIAL-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(30).
           02 M1      PIC 999.
           02 M2      PIC 999.
           02 M3      PIC 999.
       WORKING-STORAGE SECTION.
       01  TM         PIC 999.
       01  EDT-REC.
           02 EREGNO  PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 ENAME   PIC X(30).
           02 EM1     PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 EM2     PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 EM3     PIC ZZ9.
           02 FILLER  PIC XX VALUE SPACES.
           02 ETM     PIC ZZ9.
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
           DISPLAY "----------------------------------------------------
      -    "----".
           DISPLAY "                        MARK LIST".
           DISPLAY "----------------------------------------------------
      -    "----".
           DISPLAY "RNO  NAME                           M1   M2   M3  TO
      -    "TAL".
           DISPLAY "====================================================
      -    "====".
       READ-PARA.
           READ STU-FILE RECORD AT END GO TO CLOSE-PARA.
           COMPUTE TM = M1 + M2 + M3.
           MOVE REGNO TO EREGNO.
           MOVE NAME TO ENAME.
           MOVE M1 TO EM1.
           MOVE M2 TO EM2.
           MOVE M3 TO EM3.
           MOVE TM TO ETM.
           DISPLAY EDT-REC.
           GO TO READ-PARA.
       OPEN-PARA.
           OPEN INPUT STU-FILE.
       CLOSE-PARA.
           DISPLAY "====================================================
      -    "====".
           DISPLAY " ".
           CLOSE STU-FILE.
           STOP RUN.

Creation of Line Sequential - Student File with records having REGNO, NAME and MARKS OF THREE SUBJECTS.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUDENT-FILE-SEQUENTIAL-FILE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STU.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO   PIC 999.
           02 NAME    PIC X(30).
           02 M1      PIC 999.
           02 M2      PIC 999.
           02 M3      PIC 999.
       WORKING-STORAGE SECTION.
       77  NOS        PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM OPEN-PARA.
           DISPLAY "Enter the Number of Students : ".
           ACCEPT NOS.
           PERFORM GET-DATA NOS TIMES.
           PERFORM CLOSE-PARA.
           STOP RUN.
       OPEN-PARA.
           OPEN OUTPUT STU-FILE.
       GET-DATA.
           DISPLAY "Enter the Register  No : ".
           ACCEPT REGNO.
           DISPLAY "Enter the Name : ".
           ACCEPT NAME.
           DISPLAY "Three Marks : ".
           ACCEPT M1.
           ACCEPT M2.
           ACCEPT M3.
           WRITE STU-REC.
       CLOSE-PARA.
           CLOSE STU-FILE.

Derive two classes triangle and rectangle from the base class shape having data members length and breadth. Create functions to find the area of the triangle and the rectangle by runtime polymorphism

#include<iostream.h>
#include<conio.h>
class shape
{
   protected:
      double x;
      double y;
   public:
      virtual void display(){}
      void getdata(){cout<<"\nEnter x and y\n";cin>>x>>y;}
};
class triangle:public shape
{
   public:
      void display(){cout<<"\nArea  of triangle="<<(x*y*0.5);}
};
class rectangle: public shape
{
   public:
      void display(){cout<<"\nArea of rectangle="<<(x*y);}
};
void main()
{
   clrscr();
   shape *ptr;
   triangle t;
   rectangle r;
   ptr=&t;
   ptr->getdata();
   ptr->display();
   ptr=&r;
   ptr->getdata();
   ptr->display();
   getch();
}

Please make modifications

Write a program in CPP to automate a banking system by facilitating creation of accounts, deposit, withdrawal and searching using files. Use an appropriate Bank class.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
class DEPOSITOR
{
      int acno;
      char name[30];
      int balance;
   public:
      void getdata(void);
      void showdata(void);
      void deposit(int);
      void withdraw(int);
};
void DEPOSITOR::deposit(int d_amt)
{
   balance = balance + d_amt;
}
void DEPOSITOR::withdraw(int w_amt)
{
   if (w_amt > balance)
      cout << "No sifficient Amount in the Account"<<endl;
   else
      balance = balance - w_amt;
}
void DEPOSITOR::getdata()
{
   cout<<"Enter Account No : ";
   cin >>acno;
   cout<<"Enter the Name : ";
   cin >>name;
   cout<<"Enter Amount : ";
   cin >>balance;
}
void DEPOSITOR::showdata()
{
   cout.setf(ios::left,ios::adjustfield);
   cout<<setw(5)<<acno;
   cout<<setw(20)<<name;
   cout<<setw(10)<<balance<<endl;
}
void main()
{
   DEPOSITOR d;
   int opt, ac;
   int a_amt;
   fstream file;
   file.open("DEPOSITOR.DAT", ios::in | ios::out);
   clrscr();
   do
   {
      d.getdata();
      file.write((char*)&d, sizeof(d));
      flushall();
      cout<<"Enter 1 to Continue...";
      cin>>opt;
   }
   while(opt==1);
   file.seekg(0);
   while (1)
   {
       cout<<"Menu"<<endl;
       cout<<"1. Deposit"<<endl;
       cout<<"2. Withdrawal"<<endl;
       cout<<"3. View"<<endl;
       cout<<"4. Exit"<<endl;
       cout<<"Enter Your Option : ";
       cin>>opt;
       if(opt==4)
   break;
       if(opt==1)
       {
   cout<<"Enter The Account Number : ";
   cin>>ac;
   cout<<"Enter The Amount to be Deposited : ";
   cin>>a_amt;
   int loc = (ac - 1)*sizeof(d);
   file.seekg(loc);
   file.read((char*)&d,sizeof(d));
   if(file.eof() != 0) break;
   d.showdata();
   d.deposit(a_amt);
   d.showdata();
      file.seekp(loc);
   file.write((char*)&d, sizeof(d));
   flushall();
       }
       if(opt==2)
       {
   cout<<"Enter The Account Number : ";
   cin>>ac;
   cout<<"Enter The Amount to be Withdrew : ";
   cin>>a_amt;
   int loc = (ac - 1)*sizeof(d);
   file.seekg(loc);
   file.read((char*)&d,sizeof(d));
   if(file.eof() != 0) break;
   d.showdata();
   d.withdraw(a_amt);
   d.showdata();
   file.seekp(loc);
   file.write((char*)&d, sizeof(d));
   flushall();
       }
       if(opt==3)
       {
   cout<<"Enter The Account Number : ";
   cin>>ac;
   int loc = (ac - 1)*sizeof(d);
   file.seekg(loc);
   file.read((char*)&d,sizeof(d));
   if(file.eof() != 0) break;
   d.showdata();
       }
   }
   cout<<"==================================================="<<endl;
   file.close();
}

Please do modifications and send to mes.murugan@gmail.com

Create a virtual base class student that stores rollno with member functions getno( ) and putno( ). From this derive a class test with data members mark1 and mark2 and member functions getmarks( ) and putmarks( ) and derive another class sports with data member score and member functions getscore( ) and putscore( ). From test and sports classes derive the class result that stores total mark. Write a CPP program to test the classes.

#include<iostream.h>
#include<conio.h>
class student
{
   protected:
      int rno;
   public:
     void getno(){cout<<"\n\n            Roll no.: ";cin>>rno;}
     void putno(){cout<<"\n            Roll no.:"<<rno;}
};
class test : virtual public student
{
   protected :
      int m1,m2;
   public:
      void getmark(){cout<<"Marks of 2 subjects : ";cin>>m1>>m2;}
      void putmark(){cout<<"\nMarks of 2 subjects : "<<m1<<","<<m2;}
};
class sports : virtual  public student
{
   protected:
      int score;
   public:
      void getscore(){cout<<"        Sports mark : ";cin>>score;}
      void putscore(){cout<<"\n        Sports mark : "<<score;}
};
class result:public test,public sports
{
      int total;
   public:
      void display(){total=m1+m2+score;putno();putmark();putscore();
       cout<<"\n        Total Marks : "<<total;}
};
void main()
{
   result r[10];
   int n,i;
   clrscr();
   cout<<"\n Enter no: of students : ";
   cin>>n;
   clrscr();
   cout<<"\n\n  Enter details of student\n";
   for(i=1;i<=n;i++)
   {
      cout<<"\n Enter details of student : "<<i;
      r[i].getno();
      r[i].getmark();
      r[i].getscore();
   }
   clrscr();
   cout<<"\n Details of student\n\n";
   for(i=1;i<=n;i++)
   {
      cout<<"\n\n---------------------------------------------";
      cout<<"\n Details of student : "<<i<<endl;
      r[i].display();
      cout<<"\n\n---------------------------------------------";
   }
   getch();
}

A publication company that markets both book and audio-cassettes. Create a class “publication” that stores the title and price. From this class derive two classes “book” which adds a page count and “tape” which adds a playing time in minutes. Each of the three classes have a display function to display the details of the book and tape. Implement this with the use of runtime polymorphism.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class publication
{
   protected:
      char title[30];
      float price;
   public:
      publication(char *s, float a){strcpy(title,s);price=a;}
      virtual void display(){}
};
class book: public publication
{
      int pages;
   public:
      book(char *s, float a, int p):publication(s,a){pages=p;}
      void display();
};
class tape: public publication
{
      float time;
   public:
      tape(char *s, float a, float t):publication(s,a){time=t;}
      void display();
};
void book::display(){cout<<endl<<"    Title : "<<title
    <<endl<<"    Pages : "<<pages
    <<endl<<"    Price : "<<price;}
void tape::display(){cout<<endl<<"    Title : "<<title
    <<endl<<"Play Time : "<<time<<" Minutes"
    <<endl<<"    Price : "<<price;}
void main()
{
   char * title = new char[30];
   float price, time;
   int pages;
   clrscr();

   // Book Details
   cout<<endl<<"Enter Book Details"<<endl;
   cout<<"Title : ";gets(title);
   cout<<"Price : ";cin>>price;
   cout<<"Pages : ";cin>>pages;

   book book1(title,price,pages);

   // Tape Details
   cout<<endl<<"Enter Tape Details"<<endl;
   cout<<"Title : ";gets(title);
   cout<<"Price : ";cin>>price;
   cout<<"Play Time(in Mins) : ";cin>>time;

   tape tape1(title,price,time);

   publication* list[2];
   list[0]=&book1;
   list[1]=&tape1;

   cout<<endl<<"------------------------------";
   cout<<endl<<"Media Details";
   cout<<endl<<"-------------";
   cout<<endl<<"Book Details";
   cout<<endl<<"------------------------------";
   list[0]->display();
   cout<<endl<<"==============================";
   cout<<endl<<"Tape Details";
   cout<<endl<<"------------------------------";
   list[1]->display();
   cout<<endl<<"==============================";
   getch();
}

A publication company that markets both book and audio-cassettes. Create a class “publication” that stores the title and price. From this class derive two classes “book” which adds a page count and “tape” which adds a playing time in minutes. Each of the three classes should have a getdata( ) and putdata( ) function. Write a main function to test the book and tape classes by creating instances of them, and fill their data with getdata( ), and then displaying the data with putdata( )

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class publication
{
      char title[30];
      float price;
   public:
      void getdata(){cout<<endl<<"Enter Title : ";gets(title);
       cout<<"Enter Price : ";cin>>price;}
      void putdata(){cout<<endl<<"      Title : "<<title
    <<endl<<"      Price : "<<price;}
};
class book:public publication
{
      int pagecount;
      publication p;
   public:
      void getdata(){p.getdata();cout<<"Enter Pages : ";cin>>pagecount;}
      void putdata(){p.putdata();cout<<endl<<"No of Pages : "<<pagecount;}
};
class tape:public publication
{
      float p_time;
      publication p;
   public:
      void getdata(){p.getdata();cout<<" Enter Time : ";cin>>p_time;}
      void putdata(){p.putdata();cout<<endl<<"  Play Time : "<<p_time;}
};
void main()
{
   book B;
   tape T;
   clrscr();
   cout<<endl<<"Enter Details of Book";
   cout<<endl<<"---------------------";
   B.getdata();
   cout<<endl<<"Enter Details of Tape";
   cout<<endl<<"---------------------";
   T.getdata();
   cout<<endl<<"Book Details";
   cout<<endl<<"------------";
   B.putdata();
   cout<<endl<<"==================================";
   cout<<endl<<"Tape Details";
   cout<<endl<<"------------";
   T.putdata();
   cout<<endl<<"==================================";
   getch();
}

Create a class employee with employee no, name and salary. Write a menu driven CPP program (i) to create an employee database (ii) to display the content of the database and (iii) to sort the database.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<iomanip.h>
struct Employee
{
   int eno;
   char name[30];
   float salary;
};
void input(Employee E[10], int n)
{
   for(int i=0;i<n;i++)
   {
     cout<<"\nEnter Employee Number : ";
     cin>>E[i].eno;
     cout<<"\n           Enter Name : ";
     gets(E[i].name);
     cout<<"\n         Enter Salary : ";
     cin>>E[i].salary;
   }
}
void show(Employee E[10], int n)
{
     cout<<endl<<"               The Employee Details"<<endl;
     cout<<endl<<"--------------------------------------------------";
     cout<<endl<<"Emp.No    Name of Employee              Salary";
     cout<<endl<<"--------------------------------------------------";
     for(int i=0;i<n;i++)
     {
 cout.setf(ios::left, ios::adjustfield);
 cout<<endl<<setw(10)<<E[i].eno;
 cout<<setw(30)<<E[i].name;
 cout<<setw(10)<<E[i].salary;
     }
     cout<<endl<<"==================================================";
}
void main()
{
     int n, ch, i, j; Employee E[30];
     char choice;
     do
     {
 clrscr();
 cout<<"\n-----MENU-----\n";
 cout<<"\n1. Enter details of employee";
 cout<<"\n2. Sort in descending order of salary";
 cout<<"\n3. Display the details";
 cout<<"\n4. Exit from program";
 cout<<"\n\nEnter your choice : ";
 cin>>ch;
 switch(ch)
 {
   case 1: cout<<"\nEnter the number of Eemployees : ";
    cin>>n;
    input(E,n);
    cout<<"\nThe database is created now";
    cout<<"\n==========================="<<endl;
    break;
   case 2: Employee temp;
    for(i=0;i<n-1;i++)
    {
       for(j=0;j<n-1-i;j++)
       {
   if(E[j].salary<E[j+1].salary)
   {
     temp = E[j];
     E[j] = E[j+1];
     E[j+1] = temp;
   }
       }
    }
    cout<<"\nThe database is sorted now";
    cout<<"\n=========================="<<endl;
    break;
   case 3: show(E,n);
    break;
   case 4: exit(0);
   default:
    cout<<endl<<"Wrong Choice"<<endl;
 }
 cout<<"\n\nDo you want to continue (Y/y) : ";
 cin>>choice;
     }while( choice=='Y'|| choice=='y');
}

Create a class "string" as user defined string type. Include constructors to create and initialize a string. Overload the operators + and <= to add and compare two strings.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class string
{
      char str[100];
   public:
      string(){strcpy(str,"");}
      string(char a[100]){strcpy(str,a);}
      void showstr(){cout<<str;}
      string operator +(string);
      int operator <=(string);
};
string string::operator +(string str2)
{
   string str3;
   strcpy(str3.str, str);
   strcat(str3.str,str2.str);
   return(str3);
}
int string::operator <=(string str2)
{
   if (strcmp(str,str2.str) > 0)
      return(0);
   else
      return(1);
}
void main()
{
   char s1[100], s2[100];
   clrscr();
   cout<<"Enter the First String : ";
   gets(s1);
   cout<<"Enter the Second String : ";
   gets(s2);
   string so1(s1), so2(s2), so3;
   cout<<endl<<"First String = ";
   so1.showstr();
   cout<<endl<<"------------------------------------------";
   cout<<endl<<"Second String = ";
   so2.showstr();
   cout<<endl<<"------------------------------------------";
   so3=so1+so2;
   cout<<endl<<"The Concatenated String = ";
   so3.showstr();
   cout<<endl<<"------------------------------------------";
   if (so1<=so2)
      cout<<endl<<"String-1 <= String-2";
   else
      cout<<endl<<"String-1 > String-2";
   cout<<endl<<"==========================================";
   getch();
}

CPP Program for implementing various Matrix Operations

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void matread(int m[10][10],int r,int c)
{
   int i,j;
   cout<<endl<<"Enter the Elements of the Matrix : ";
   for(i=0;i<r;i++)
      for(j=0;j<c;j++)
  cin>>m[i][j];
}
void matdisplay(int m[10][10],int r,int c)
{
   int i,j;
   cout<<"The Resultant Matrix : ";
   for(i=0;i<r;i++)
   {
      cout<<endl;
      for(j=0;j<c;j++)
  cout<<m[i][j]<<" ";
   }
}
void matadd(int m1[10][10], int m2[10][10], int m3[10][10], int r, int c)
{
   int i,j;
   for(i=0;i<r;i++)
      for(j=0;j<c;j++)
  m3[i][j]=m1[i][j]+m2[i][j];
}
void matsub(int m1[10][10], int m2[10][10], int m3[10][10], int r, int c)
{
   int i,j;
   for(i=0;i<r;i++)
      for(j=0;j<c;j++)
  m3[i][j]=m1[i][j]-m2[i][j];
}
void matprod(int m1[10][10], int m2[10][10], int m3[10][10], int r, int c, int rc)
{
   int i,j,k;
   for(i=0;i<r;i++)
      for(j=0;j<c;j++)
      {
  m3[i][j]=0;
  for(k=0;k<rc;k++)
     m3[i][j]+=m1[i][k]*m2[k][j];
      }
}
void transpose(int m1[10][10],int m2[10][10], int r, int c)
{
   int i,j;
   for(i=0;i<r;i++)
      for(j=0;j<c;j++)
  m2[i][j]=m1[j][i];
}
void rowsum(int m[10][10], int r, int c)
{
   int i,j,rs;
   cout<<endl<<"Sum of each Row elements";
   cout<<endl<<"------------------------";
   for(i=0;i<r;i++)
   {
      rs=0;
      for(j=0;j<c;j++)
  rs+=m[i][j];
      cout<<endl<<rs;
   }
   cout<<endl<<"========================";
}
void colsum(int m[10][10], int r, int c)
{
   int i,j,cs;
   cout<<endl<<"Sum of each Column elements";
   cout<<endl<<"---------------------------";
   for(j=0;j<c;j++)
   {
      cs=0;
      for(i=0;i<r;i++)
  cs+=m[i][j];
      cout<<endl<<cs;
   }
   cout<<endl<<"===========================";
}
void maindiag(int m[10][10], int r, int c)
{
   int i,mds=0;
   if(r==c)
   {
      for(i=0;i<r;i++)
  mds+=m[i][i];
      cout<<endl<<"The Sum of Mian Diagonal Elements = "<<mds;
   }
   else
      cout<<endl<<"Invalid Matrix : This is not Square Matrix";
}
void offdiag(int m[10][10], int r, int c)
{
   int i,j,ods=0;
   if(r==c)
   {
      for(i=0;i<r;i++)
      {
  for(j=0;j<r;j++)
     if(i+j == r-1)
        ods+=m[i][j];
      }
      cout<<endl<<"The Sum of Off Diagonal Elements = "<<ods;
   }
   else
      cout<<endl<<"Invalid Matrix : This is not Square Matrix";
}
void uptrisum(int m[10][10], int r, int c)
{
   int i,j,uts=0;
   if(r==c)
   {
      for(i=0;i<r;i++)
      {
  for(j=0;j<r;j++)
     if(i<j)
        uts+=m[i][j];
      }
      cout<<endl<<"The Sum of Upper Triangular Elements = "<<uts;
   }
   else
      cout<<endl<<"Invalid Matrix : This is not Square Matrix";
}
void lowtrisum(int m[10][10], int r, int c)
{
   int i,j,lts=0;
   if(r==c)
   {
      for(i=0;i<r;i++)
      {
  for(j=0;j<r;j++)
     if(i>j)
        lts+=m[i][j];
      }
      cout<<endl<<"The Sum of Lower Triangular Elements = "<<lts;
   }
   else
      cout<<endl<<"Invalid Matrix : This is not Square Matrix";
}
void main()
{
   clrscr();
   int r1,c1,r2,c2,ch;
   int A[10][10],B[10][10],C[10][10];
   char yn;
   cout<<endl<<"Enter the order of the First Matrix : ";
   cin>>r1>>c1;
   matread(A,r1,c1);
   cout<<endl<<"Enter the order of the Second Matrix : ";
   cin>>r2>>c2;
   matread(B,r2,c2);
   do
   {
      clrscr();
      cout<<endl<<" Menu";
      cout<<endl<<"------";
      cout<<endl<<" 1. Matrix Addition"
   <<endl<<" 2. Matrix Subtraction"
   <<endl<<" 3. Matrix Multiplication"
   <<endl<<" 4. Transpose of Matrix"
   <<endl<<" 5. Sum of Elements in Each Row"
   <<endl<<" 6. Sum of Elements in Each Column"
   <<endl<<" 7. Sum of Mian Diagonal Elements"
   <<endl<<" 8. Sum of Off Diagonal Elements"
   <<endl<<" 9. Sum of Upper Triangular Elements"
   <<endl<<"10. Sum of Lower Triangular Elements"
   <<endl<<endl<<"Enter Your Choice : ";
      cin>>ch;
      switch (ch)
      {
  case 1: if((r1==r2)&&(c1==c2))
   {
     matadd(A,B,C,r1,c1);
     matdisplay(C,r1,c1);
   }
   else
     cout<<"Matrices are not confirmable for Addition";
   break;
  case 2: if((r1==r2)&&(c1==c2))
   {
     matsub(A,B,C,r1,c1);
     matdisplay(C,r1,c1);
   }
   else
   cout<<"Matrices are not confirmable for subtraction";
   break;
  case 3:if(c1==r2)
   {
     matprod(A,B,C,r1,c2,c1);
     matdisplay(C,r1,c2);
   }
   else
     cout<<"Matrices are not confirmable for multiplication";
   break;
  case 4: transpose(A,C,r1,c1);
   matdisplay(C,r1,c1);
   break;
  case 5: rowsum(A,r1,c1);
   break;
  case 6: colsum(A,r1,c1);
   break;
  case 7: maindiag(A,r1,c1);
   break;
  case 8: offdiag(A,r1,c1);
   break;
  case 9: uptrisum(A,r1,c1);
   break;
  case 10:lowtrisum(A,r1,c1);
   break;
      }
   cout<<endl<<endl<<"To Continue...(Y/y) : ";
   cin>>yn;
   }
   while(toupper(yn)=='Y');
}

COBOL Program for Printing Mark List using a table

A student record contains register no, name, marks of three subjects, total marks and result(use appropriate picture clause). Write a program in COBOL to accept required information of n number of students and process and print MARK LIST for each student in a neat format.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUDENT-TABLE-MARKLIST
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  STUDENT.
           02 STU-REC OCCURS 100 TIMES.
              03 REGNO  PIC 999.
              03 NAME   PIC X(30).
              03 M1     PIC 999.
              03 M2     PIC 999.
              03 M3     PIC 999.
              03 TM     PIC 999.
              03 RESULT PIC X(20).
       01  E-STU-REC.
           02 E-REGNO   PIC ZZ9.
           02 E-M1      PIC ZZ9.
           02 E-M2      PIC ZZ9.
           02 E-M3      PIC ZZ9.
           02 E-TM      PIC ZZ9.
       01  NOS   PIC 999.
       01  I     PIC 999.
       01  PAUSE PIC X.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY "Enter the Number of Students : ".
           ACCEPT NOS.
           PERFORM READ-PARA VARYING I FROM 1 BY 1 UNTIL I > NOS.
           PERFORM PROCESS-PARA VARYING I FROM 1 BY 1 UNTIL I > NOS.
           PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > NOS.
           DISPLAY " ".
           STOP RUN.
       READ-PARA.
           DISPLAY "Enter the Register Number : ".
           ACCEPT REGNO(I).
           DISPLAY "Enter the Name : ".
           ACCEPT NAME(I).
           DISPLAY "Enter three Marks : ".
           ACCEPT M1(I).
           ACCEPT M2(I).
           ACCEPT M3(I).
       PROCESS-PARA.
           COMPUTE TM(I) = M1(I) + M2(I) + M3(I).
           IF TM(I) NOT < 240
              MOVE "Distinction" TO RESULT(I)
           ELSE IF TM(I) NOT < 180
              MOVE "First Class" TO RESULT(I)
           ELSE IF TM(I) NOT < 150
              MOVE "Passed" TO RESULT(I)
           ELSE
              MOVE "Failed" TO RESULT(I).
       DISP-PARA.
           MOVE REGNO(I) TO E-REGNO.
           MOVE M1(I) TO E-M1.
           MOVE M2(I) TO E-M2.
           MOVE M3(I) TO E-M3.
           MOVE TM(I) TO E-TM.
           DISPLAY(01 01) ERASE.
           DISPLAY(01 02) "-----------------------------------".
           DISPLAY(02 05) "         MARK LIST".
           DISPLAY(03 02) "-----------------------------------".
           DISPLAY(05 05) "Register No. : " E-REGNO.
           DISPLAY(06 05) "        Name : " NAME(I).
           DISPLAY(07 05) " Marks for".
           DISPLAY(08 05) "       Sub-1 : " E-M1.
           DISPLAY(09 05) "       Sub-2 : " E-M2.
           DISPLAY(10 05) "       Sub-3 : " E-M3.
           DISPLAY(11 02) "-----------------------------------".
           DISPLAY(12 05) " Total Marks : " E-TM.
           DISPLAY(13 05) "      Result : " RESULT(I).
           DISPLAY(14 02) "===================================".
           ACCEPT PAUSE.


COBOL Program for preparing Result of Students using tables


A student record contains register no, name, marks of three subjects, total marks and result(use appropriate picture clause). Write a program in COBOL to accept required information of n number of students and process and print the results in a neat format.

    
    
       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUDENT-TABLE-MARKLIST.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  STUDENT.
           02 STU-REC OCCURS 100 TIMES.
              03 REGNO  PIC 999.
              03 FILLER PIC X.
              03 NAME   PIC X(30).
              03 M1     PIC 999.
              03 FILLER PIC X(3).
              03 M2     PIC 999.
              03 FILLER PIC X(3).
              03 M3     PIC 999.
              03 FILLER PIC X(3).
              03 TM     PIC 999.
              03 FILLER PIC X(3).
              03 RESULT PIC X(20).
       01  SL   PIC X(78) VALUE ALL "-".
       01  DL   PIC X(78) VALUE ALL "=".
       01  NOS  PIC 999.
       01  I    PIC 999.
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY "Enter the Number of Students : ".
           ACCEPT NOS.
           PERFORM READ-PARA VARYING I FROM 1 BY 1 UNTIL I > NOS.
           PERFORM PROCESS-PARA VARYING I FROM 1 BY 1 UNTIL I > NOS.
           DISPLAY SL.
           DISPLAY "                              RESULT".
           DISPLAY SL.
           DISPLAY "RGN NAME                           M1    M2    M3
      -    " TM   RESULT".
           DISPLAY DL.
           PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > NOS.
           DISPLAY DL.
           DISPLAY " ".
           STOP RUN.
       READ-PARA.
           DISPLAY "Enter the Register Number : ".
           ACCEPT REGNO(I).
           DISPLAY "Enter the Name : ".
           ACCEPT NAME(I).
           DISPLAY "Enter three Marks : ".
           ACCEPT M1(I).
           ACCEPT M2(I).
           ACCEPT M3(I).
       PROCESS-PARA.
           COMPUTE TM(I) = M1(I) + M2(I) + M3(I).
           IF TM(I) NOT < 240
              MOVE "Distinction" TO RESULT(I)
           ELSE IF TM(I) NOT < 180
              MOVE "First Class" TO RESULT(I)
           ELSE IF TM(I) NOT < 150
              MOVE "Passed" TO RESULT(I)
           ELSE
              MOVE "Failed" TO RESULT(I).
       DISP-PARA.
           DISPLAY STU-REC(I).
Scientometric and Journal Indexing 

Welcome to our Blog

All colleagues and students
I welcome all of you to this initiative. Please visit frequently this blog for new information and your valuable comments.

CPP Program


/*Illustrate the use of dereferencing operators to access the class 
members through pointers.  To implement this, define a class M 
with x and y as data members.  Define two methods. One is to input 
the values of x and y and other to find the sum.  The sum is a friend 
function and object of class M is passed as argument in sum.  
Sum will access the class members through dereferencing operators.  
Implement the program and display the results in a neat format
*/

#include<iostream.h>
#include<conio.h>
class M
{
      int x,y;
   public:
      void getdata(void){cout<<"Enter X : ";cin>>x;
			 cout<<"Enter Y : ";cin>>y;}
      friend void sum(M);
};
void sum(M m)
{
   M *pm = &m;
   int M:: *px = &M::x;
   int M:: *py = &M::y;
   cout<<endl<<"The sum = "<<pm->*px+pm->*py;
}
void main()
{
   clrscr();
   M om;
   om.getdata();
   sum(om);
   getch();
}

Alternate 

#include<iostream.h>
#include<conio.h>
class M
{
      int x,y;
   public:
      void getdata(void){cout<<"Enter X : ";cin>>x;
			 cout<<"Enter Y : ";cin>>y;}
      friend void sum(M);
};
void sum(M m)
{
   int M:: *px = &M::x;
   int M:: *py = &M::y;
   cout<<endl<<"The sum = "<<m.*px+m.*py;
}
void main()
{
   clrscr();
   M om;
   om.getdata();
   sum(om);
   getch();
}

Welcome BCA S6 Batch !!!!

Welcome BCA S6 batch students to our blog where we can make this as a medium for exchanging ideas !.I wish to share the codings with examples making this blog a vibrant one ! 
COBOL Program to Add Two Numbers.
Dear students please go through the program and do comment for doubts.

123456789012345678901234567890123456789012345678901234567890123456789012
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SUM-OF-TWO-NUMBERS.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  NUM1    PIC S999V99.
       01  NUM2    PIC S999V99.
       01  TOTAL   PIC S9(4)V99.
       01  E-TOTAL PIC ----9.99.
       01  HAI     PIC PP999.
       01  E-HAI   PIC ZZZ.9(8).
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY(01 01) SPACES.
           DISPLAY(05 05) "Enter the First Number : ".
           ACCEPT(05 32) NUM1.
           DISPLAY(07 05) "Enter the Second Number : ".
           ACCEPT(07 32) NUM2.
           COMPUTE TOTAL = NUM1 + NUM2.
           MOVE TOTAL TO E-TOTAL.
           DISPLAY(10 05) "The Sum = " E-TOTAL.
           DISPLAY(11 05) "====================".
           DISPLAY " ".
           MOVE 12 TO HAI.
           MOVE HAI TO E-HAI.
           DISPLAY E-HAI.
           STOP RUN.