C / C++ / oop

Spring 2014  OOP

Question no 2 :Capture


 

/Ahsan Saeed/
#include <iostream.h>

int main(){
int a;

char ch;

do
{
cout<<“\n\nEnter a number :”;
cin>>a;
if( a ==051 )
{
// if condition is true then print the following
cout << “ISB” << endl;
}

else
if( a ==042 )
{
// if condition is true then print the following
cout << “LAHORE” << endl;
}

else
if( a ==021 )
{
// if condition is true then print the following
cout << “KARACHI” << endl;
}

else
if( a ==0521 )
{
// if condition is true then print the following
cout << “LAHORE” << endl;
}

else
if( a ==5 )
{
// if condition is true then print the following
cout << “PESHAWAR” << endl;
}

else
cout<<“Invalid”;

}

cout<<“Start Again [press enter] / exit [ y ]” ;

cin>>ch;

{

while(ch!=’y’);

}

 


Write a program which accept principle, rate and time from user and print the  ( simple interest ).


#include<iostream>
using namespace std;

int main()
{
int p,r,t,i;
cout<<“Enter Principle : “;
cin>>p;
cout<<“Enter Rate : “;
cin>>r;
cout<<“Enter Time : “;
cin>>t;
i=(prt)/100;
cout<<“Simple interest is : “<<i;
return 0;
}

Output:

Enter Principle : 1800
Enter Rate : 5
Enter Time : 3
Simple interest is : 270

 

 

 

 

 

 

 

 

 

 

 

 

 


Write a program which input principal, rate and time from user and calculate compound interest.

CI = P(1+R/100)T – P


 

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    float P,R,T,CI;
    cout<<"Enter Principal, Rate and Time : ";
    cin>>P>>R>>T;
    CI=P*pow((1+R/100),T) - P;
    cout<<"Compound Interest is : "<<CI;
    
    return 0;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


SquareRoot PROGRAM 1 [auto loop limited oneTime]


#include<iostream>
using namespace std;
 long double sqrt(long double n)
 {
 long double x=n/2;
 for(;;)
 {
 x=0.5*(x+(n/x));
if((x*x)>=n-0.00001&&(x*x)<=n+0.00001)
 break;
 }
 return x;
 }

int main()
{

 long double n;
 cout<<"Enter no : ";
 cin>>n;
cout<<"Result : "<<sqrt(n)<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
 return 0;
}

 

 

 

SquareRoot PROGRAM 1 [infinity loop]

// PROGRAM 3 [ user intput infinity]

#include<iostream>
using namespace std;
long double sqrt(long double n)
{
long double x=n/2;
for(;;)
{
x=0.5(x+(n/x));
if((x
x)>=n-0.00001&&(x*x)<=n+0.00001)
break;
}
return x;
}

int main()
{

long double n;

for(;;)
{
cout<<“Enter no : “;

cin>>n;
cout<<“Result : “<<sqrt(n)<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
}
return 0;

}

 

 

SquareRoot PROGRAM 1 [user input limit ]

#include<iostream>
using namespace std;
 long double sqrt(long double n)
 {
 long double x=n/2;
 for(;;)
 {
 x=0.5*(x+(n/x));
if((x*x)>=n-0.00001&&(x*x)<=n+0.00001)
 break;
 }
 return x;
 }

int main()
{

 long double LimitByUser,LimitByUserLoop,n;
cout<< " SquareRoot \n\n";
 cout<<"user limit :";
 cin>>LimitByUser;

 for(LimitByUserLoop=1;LimitByUserLoop<=LimitByUser;LimitByUserLoop++)
 {
cout << " Enter value of "<<LimitByUserLoop <<"\t" ;

 cin>>n;
cout<<" Result : "<<sqrt(n)<<endl;
 }

for(LimitByUserLoop=1;LimitByUserLoop<=LimitByUser;LimitByUserLoop++)
 {
 
cout<<" \n\n || Result : "<< LimitByUserLoop <<sqrt(n)<<endl;
}
return 0; 
 
}

 

pro

 

 

 

 

 


STUDENTS Database in C


#include <stdio.h>
struct student{
char name[25];
int roll;
float marks;
};
int main(){
struct student s[10];
int i;
printf(“Enter information of students:\n”);
for(i=0;i<10;++i)
{
s[i].roll=i+1;
printf(“\nFor roll number %d\n”,s[i].roll);
printf(“Enter name: “);
scanf(“%s”,s[i].name);
printf(“Enter marks: “);
scanf(“%f”,&s[i].marks);
printf(“\n”);
}
printf(“Displaying information of students:\n\n”);
for(i=0;i<10;++i)
{
printf(“\nInformation for roll number %d:\n”,i+1);
printf(“Name: “);
puts(s[i].name);
printf(“Marks: %.1f”,s[i].marks);
}
return 0;
}

 

OUT PUT :rec.PNG

 


EVENT STUDENT REGISTRATION MANAGEMENT SYSTEM  :

Buy $4.75

12

 

 

 

 

 

 

 

BANK MANAGEMENT SYSTEM

Buy $5:00

1b 2b

 


How To Change Text Color of C/C++ Console Application

 Codes:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

 

 

 

Example of color :  
#include <stdio.h>
#include <stdlib.h>

int main()
{

//System (“COLOR Back-Ground-Color is 0 and Font-Color is 4 “);

system(“COLOR 0C”);
printf(“Welcome to the color changing application!\n”);
printf(“Press any key to change the background color!\n”);

 

printf(“Muhammad Ahsan | Daniel | PROGRAMMER”);
getchar();

return 0;

 


 

Create Mark Sheet Using Structure

#include<stdio.h>
#include<conio.h>
#define STU 3
#define SUB 3
void main()
{
int k,i;
struct student
{
int rno;
char name[20];
int marks[2];
int total;
float avg;
}sk;
for(k=1;k<=STU;k++)
{
printf(“Enter the roll no and name of the student %d:”,k);
scanf(“%d%s”,&sk.rno,&sk.name);
printf(“Enter the marks:”);
for(i=0;i<sub;i++)
{
scanf(“%d”,&sk.marks[i]);
sk.total=sk.total+sk.marks[i];
}
sk.avg=sk.total/SUB;
}
printf(“\nRollno\tName\tMarks\tTotal\tAvg\n”);

for(k=1;k<=STU;k++)
{
printf(“%d\t%s\t”,sk.rno,sk.name);
for(i=0;i<sub;i++)
printf(“%d “,sk.marks[i]);
printf(“%d\t%.3f\n”,sk.total,sk.avg);
}
getch();
}


#include<stdio.h>
        struct student
        {
          int sub1;
          int sub2;
          int sub3;
        };
            void main()
        {
             struct student s[10];
             int i,total=0;
             clrscr();
             for(i=0;i<=2;i++)
                 {
                        printf("\nEnter Marks in Three Subjects = ");
                        scanf("%d%d%d",& s[i].sub1,&s[i].sub2,&s[i].sub3);
                        total=s[i].sub1+s[i].sub2+s[i].sub3;
                        printf("\nTotal marks of s[%d] Student= %d",i,total);
                 }
                        getch();
         }

 

 


#include
#include
#include

class stud
{
int rno,m1,m2,m3,tot;
char name[20];
float avg;

public:
void getdata()
{
cout<<“\n\nEnter the rno:”;
cin>>rno;
cout<<“Enter the name:”;
cin>>name;
cout<<“Enter the first marks:”;
cin>>m1;
cout<<“Enter the second mark:”;
cin>>m2;
cout<<“Enter the third mark:”;
cin>>m3;
}

void caldata()
{
tot=m1+m2+m3;
avg=tot/3;
}

void putdata()
{
cout<<“\n”<<rno<< “\t=”” “;=”” <br=””> cout<<name<<“\t\t”; <br=””> cout<<m1<<“\t”; <br=””> cout<<m2<<“\t”; <br=””> cout<<m3<<“\t”; <br=””> cout<<tot<<“\t”; <br=””> cout<<avg; <br=””>if(avg>=80)
cout<<“\t A”;
else if(avg>=60&&avg<=79)
cout<<“\t B”;
else if(avg>=40&&avg<=59)
cout<<“\t C”;
else
cout<<“\t FAIL”;
}
};

void main()
{
int i,n;
stud s[20];
clrscr();
cout<<“\n\t\t\t STUDENT MARKSHEET”;
cout<<“\n\t\t\t ~~~~~~~~~~~~~~~~~~”;
cout<<“\n ENTER THE NUMBER OF STUDENTS:”;
cin>>n;
for(i=0;i<n;i++) <br=””>{
s[i].getdata();
s[i].caldata();
}
cout<<“\n\nRNO”<<“\t”<<“NAME”<<“\t\t”<<“M1″<<“\t”<<“M2″<<“\t”<<“M3″<<“\t”<<“TOT”<<“\t”<<“AVG”<<“\t”<<“GRADE”<<“\n”;
cout<<“_______________________________________________________________”;
for(i=0;i<n;i++) <br=””>{
s[i].putdata();
}
getch();
}

OUTPUT:

STUDENT MARKSHEET
~~~~~~~~~~~~~~~~~~

ENTER THE NUMBER OF STUDENTS : 3

Enter the rno:1
Enter the name:hussain
Enter the first marks:89
Enter the second mark:67
Enter the third mark:56

Enter the rno:2
Enter the name:kumar
Enter the first marks:45
Enter the second mark:67
Enter the third mark:89

Enter the rno:3
Enter the name:raju
Enter the first marks:78
Enter the second mark:98
Enter the third mark:90

RNO NAME M1 M2 M3 TOT AVG GRADE


1 hussain 89 67 56 212 70 B
2 kumar 45 67 89 201 67 B
3 raju 78 98 90 266 88 A

 

 

 


C Program to Store Information(name, roll and marks) of a Student Using Structure

#include <stdio.h>
struct student{
    char name[50];
    int roll;
    float marks;
};
int main(){
    struct student s;
    printf("Enter information of students:\n\n");
    printf("Enter name: ");
    scanf("%s",s.name);
    printf("Enter roll number: ");
    scanf("%d",&s.roll);
    printf("Enter marks: ");
    scanf("%f",&s.marks);
    printf("\nDisplaying Information\n");
    printf("Name: %s\n",s.name);
    printf("Roll: %d\n",s.roll);
    printf("Marks: %.2f\n",s.marks);
    return 0;
}

C++ Structure and Function

Example 1: C++ Structure and Function

#include <iostream>
using namespace std;

struct  person {
    char name[50];
    int age;
    float salary;
};

void displayData(person);   // Function declaration

int main() {

    person p;

    cout << "Enter Full name: ";
    cin.get(p.name, 50);
    cout << "Enter age: ";
    cin >> p.age;
    cout << "Enter salary: ";
    cin >> p.salary;

    displayData(p);    // Function call with structure variable as arugment

    return 0;
}

void displayData(person p1) {


    cout << "\nDisplaying Information." << endl;
    cout << "Name: " << p1.name << endl;
    cout <<"Age: " << p1.age << endl;
    cout << "Salary: " << p1.salary;
    
}

C++ Functions

  1. Library Function
  2. User-defined Function

Example 1: Library Function [sqrt] =SquareRoot


# include <iostream>
#include <cmath>

using namespace std;

int main() {
    double number, squareRoot;
    cout<<"Enter a number: ";
    cin>>number;

/* sqrt() is a library function to calculate square root */
    squareRoot = sqrt(number);
    cout<<"Square root of "<<number<<" = "<<squareRoot;
    return 0;
}

Example 1: User Define Function

# include <iostream>
using namespace std;

int add(int, int);            //Function prototype(declaration)

int main() {
    int num1, num2, sum;
    cout<<"Enters two numbers to add: ";
    cin>>num1>>num2;
    sum = add(num1,num2);         //Function call
    cout<<"Sum = "<<sum;
    return 0;
}

int add(int a,int b) {            //Function declarator
    int add;
    add = a+b;
    return add;                 //Return statement
}

C++ Recursion

#include <iostream>
using namespace std;

int factorial(int);

int main() {
    int n;
    cout<<"Enter a number to find factorial: ";
    cin>>n;
    cout<<"Factorial of "<<n<<" = "<<factorial(n);
    return 0;
}

int factorial(int n) {
    if (n>1) {
        return n*factorial(n-1);
    }
    else {
        return 1;
    }
}

Passing Array to a Function in C++ Programming

Example 1: Passing One-dimensional Array to a Function

C++ Program to display marks of 5 students by passing one-dimensional array to a function.

#include <iostream>
using namespace std;
void display(int marks[5]);

int main() {
    int marks[5] = {88, 76, 90, 61, 69};
    display(marks);
    return 0;
}

void display(int m[5]) {
    cout<<"Displaying marks: "<<endl;
    for (int i = 0; i <5; ++i) {
        cout<<"Student "<<i+1<<": "<<m[i]<<endl;
    }
}

Passing Multidimensional Array to a Function

 

Example 2: Passing Multidimensional Array to a Function

C++ Program to display the elements of two dimensional array by passing it to a function.

#include <iostream> 
using namespace std;
void display(int n[3][2]);

int main() {
        int num[3][2] = {
        {3, 4},
        {9, 5},
        {7, 1}

    };
    display(num);
    return 0;
}
void display(int n[3][2]) {

    cout<<"Displaying Values: "<<endl;
    for(int i = 0;  i < 3; ++ i) {
        for(int j = 0; j < 2; ++j) {
            cout<<n[i][j]<<" ";
        }
    }
}



 C++ Pointers [Basic Code]

/ my first pointer
#include <iostream>
using namespace std;

int main ()
{
  int firstvalue, secondvalue;
  int * mypointer;

  mypointer = &firstvalue;
  *mypointer = 10;
  mypointer = &secondvalue;
  *mypointer = 20;
  cout << "firstvalue is " << firstvalue << '\n';
  cout << "secondvalue is " << secondvalue << '\n';
  return 0;
}

 C++ Pointers to Structure

Example 1: Pointers to Structure

#include <iostream>
using namespace std;

struct Distance {
    int feet;
    float inch;
};

int main() {
    Distance *ptr, d;

    ptr = &d;
    
    cout << "Enter feet: ";
    cin >> (*ptr).feet;
    cout << "Enter inch: ";
    cin >> (*ptr).inch;
 
    cout << "Displaying information." << endl;
    cout << "Distance = " << (*ptr).feet << " feet " << (*ptr).inch << " inches";

    return 0;
}


C++ Pointers and Arrays

 Example 1: C++ Pointers and Arrays

C++ Program to display address of elements of an array using both array and pointers

#include <iostream>
using namespace std;

int main() {
    float a[5];
    float *ptr;
    
    cout << "Displaying address using arrays: "<<endl;
    for (int i = 0; i < 5; ++i) {
        cout << "&a[" << i << "] = " << &a[i] <<endl;
    }

    ptr = a;   // ptr = &a[0]
    cout<<"\nDisplaying address using pointers: "<< endl;
    for (int i = 0; i < 5; ++i) {
        cout << "ptr + " << i << " = "<<ptr+i <<endl;
    }

    return 0;
}

Example 1: C++ Pointers and Arrays

C++ Program to display address of elements of an array using both array and pointers

#include <iostream>
using namespace std;

int main() {
    float a[5];
    float *ptr;
    
    cout << "Displaying address using arrays: "<<endl;
    for (int i = 0; i < 5; ++i) {
        cout << "&a[" << i << "] = " << &a[i] <<endl;
    }

    ptr = a;   // ptr = &a[0]
    cout<<"\nDisplaying address using pointers: "<< endl;
    for (int i = 0; i < 5; ++i) {
        cout << "ptr + " << i << " = "<<ptr+i <<endl;
    }

    return 0;
}

C++ Object and Class

Example to Explain Working of Object and Class in C++ Programming


/* Program to illustrate working of Objects and Class in C++ Programming */
#include <iostream>
using namespace std;
class temp
{
    private:
        int data1;
        float data2;
    public:
       void int_data(int d){
          data1=d;
          cout<<"Number: "<<data1;
         }
       float float_data(){
           cout<<"\nEnter data: ";
           cin>>data2;
           return data2;
         }
};
 int main(){
      temp obj1, obj2;
      obj1.int_data(12);
      cout<<"You entered "<<obj2.float_data();
      return 0;
 }
 /*#include<iostream.h>
//using namespace std;

class BuckysClass{
public:
 void coolSaying(){
 cout<<"hello ahsan"<<endl;

 }
};

void main()
{
 BuckysClass buckysObject;
 buckysObject.coolSaying();

}*/

#include<iostream.h>

class AhsanClass{

 public:
 void simpleText()
 {
 cout<<"Welcome user";
 }

};

void main()
{
 AhsanClass ahsanObject;
 ahsanObject.simpleText();

}

Example 2: C++ Pointer and Array

C++ Program to insert and display data entered by using pointer notation.

#include <iostream>
using namespace std;

int main() {
 
 float a[5];
 
// Inserting data using pointer notation
 cout << "Enter 5 numbers: ";
 for (int i = 0; i < 5; ++i) {
 cin >> *(a+i) ;
 }

 
// Displaying data using pointer notation
 cout << "Displaying data: " << endl;
 
 for (i=0;i<5;i++){
 cout <<*(a+i)<<endl;
 }

 return 0;
}

C++ Arrays

type array_name[size];

Consider this code.

int test[85];

Array Elements

int age[5];
Elements of an array in C++ Programming


Example 1: C++ Array

C++ Program to store 5 numbers entered by user in an array and display first and last number only.

#include <iostream>
using namespace std;

int main() {
    int n[5];
    cout<<"Enter 5 numbers: ";
/*  Storing 5 number entered by user in an array using for loop. */
    for (int i = 0; i < 5; ++i) {
        cin>>n[i];
    }
    
    cout<<"First number: "<<n[0]<<endl;  // first element of an array is n[0]
    cout<<"Last number: "<<n[4];        // last element of an array is n[SIZE_OF_ARRAY - 1]
    return 0;
}

C++ Multidimensional Arrays

int x[3][4];
Elements in two dimensional array in C++ Programming

Three dimensional also array works in similar way. For example:

float x[2][4][3];

Multidimensional Array Initialisation

int test[2][3] = {2, 4, -5, 9, 0, 9};
int  test[2][3] = { {2, 4, 5}, {9, 0 0}};

nitialisation of three dimensional array

int test[2][3][4] = {3, 4, 2, 3, 0, -3, 9, 11, 23, 12, 23, 
                 2, 13, 4, 56, 3, 5, 9, 3, 5, 5, 1, 4, 9};

Better way to initialise this array with same elements as above.

int test[2][3][4] = { 
                     { {3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12, 23, 2} },
                     { {13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4, 9} }
                 };

Example 1: Two Dimensional Array

C++ Program to display all elements of an initialised two dimensional array.

#include <iostream>
using namespace std;

int main() {
    int test[3][2] = {
        {2, -5},
        {4, 0},
        {9, 1}
    };
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 2; ++j) {
            cout<< "test["<< i << "][" << ;j << "] = " << test[i][j]<<endl;
        }
    }
    return 0;
}

Example 3: Three Dimensional Array

C++ Program to Store value entered by user in three dimensional array and display it.

#include <iostream>
using namespace std;

int main() {
    int test[2][3][2];    // this array can store 12 elements
    cout<<"Enter 12 values: \n";
    for(int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            for(int k = 0; k < 2; ++k ) {
                cin>>test[i][j][k];
            }
        }
    }
    cout<<"\nDisplaying Value stored:"<<endl;
/* Displaying the values with proper index. */
    for(int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            for(int k = 0; k < 2; ++k ) {
                cout<< "test["<<i<<"]["<<j<<"]["<<k<<"] = "<< test[i][j][k]<<endl;
            }
        }
    }

    return 0;
}




 

 

Example : Reading and Writing to Files – fstream

#include<iostream>
#include<fstream>
using namespace std ;

int main()
{
cout<<“welcome Ahsan :”<<endl;
int sum=0, sub=0,mul=0,mod=0,div=0;

int x;

char fileName[50];
ifstream numbersFile;

cin.getline(fileName,50);
numbersFile.open(fileName);

if(!numbersFile.is_open())
{
cout<<“it failed”<<endl;
return 0;
}
while(numbersFile>>x)
{

sum=x+x;
sub=x-x;
mul=x*x;
div=x/x;
mod=x%x;
}
cout<<“The demo.txt file contain [ x ] value which is “<<x <<endl<<endl<<endl<<endl<<endl<<endl;

cout<< “This sum + of x value is : “<<sum<<endl<<endl<<endl<<endl;
cout<< “This subtraction – of x value is : “<<sub<<endl<<endl<<endl<<endl;
cout<< “This multiplication * of x value is : “<<mul<<endl<<endl<<endl<<endl;
cout<< “This division / of x value is : “<<div<<endl<<endl<<endl<<endl;
cout<< “This modulas % of x value is : “<<mod<<endl<<endl<<endl<<endl;

return 0;
}

demo2

Example : Reading and Writing to Files – fstream

if you want to make a calculator .

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream inFile;
inFile.open(“numbers.txt”);

if(inFile.fail())
{
cerr<<“Error opening file”<<endl;
exit(1);
}
int x,y,sum=0,sub=0,mul=0,div=0,mod=0,sqrx=0,sqry=0;
inFile>>x>>y;
sum=x+y;
sub=x-y;
mul=xy;
div=x/y;
mod=x%y;
sqrx=x
x;
sqry=y*y;
cout<<“Num 1 :”<<x<<endl;
cout<<“Num 2 :”<<y<<endl;
cout<<“sum of x and y :”<<sum<<endl;
cout<<“subtraction of x and y :”<<sub<<endl;
cout<<“multiplication of x and y :”<<mul<<endl;
cout<<“division of x and y :”<<div<<endl;
cout<<“modulus of x and y :”<<mod<<endl;
cout<<“square of x and y :”<<sqrx<<endl;
cout<<“square of y and y :”<<sqry<<endl;
return 0;
}

abc

Example : Create file , Writing to Files -show in console

According to this code first, automatically the file create eg: ahsan.txt where’s  your cpp file ,and when you compile the C++ file , then  the console screen show you the output in the text form  like , “The file has been created”.

#include<iostream.h>
#include<fstream.h>
//using namespace std;
int main()
{
ofstream file(“ahsan.txt”);

if(!file.is_open())
{
cout<<“unable to open the file.”;

}

else
{
file<<“write your text here which automatically show in the your text file “<<endl;

file.close();
cout<<“The file has been created. “;

}
return 0;

}

file

// file opening modes in c++

//ios_base | ios:in |
:out
:trunk
:app
:ate
:binary

#include<iostream>
#include<fstream>
using namespace std;

int main()
{ // file opening modes in c++
fstream file;
file.open(“ahsan.txt” ,ios:: in| ios:: out| ios:: trunc); //ios_base | ios:in |

if(!file.is_open())
{
cout<<“Error while opening the file.”;
}
else
{
cout<<“File opened successfully\n\n”;
cout<<“if your file ahsan.txt already exist ,\n the new file replace the first one \n and also remove the data from the first file.\n\n\n\n”;
file.close();

}

return 0;
}

Capture

 

Example :   Writing to a File in C++

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
ofstream file(“ahasn.txt”);

if(!file.is_open())
{
cout<<“unable to open file”;
}
else
{
file<<“Learning c++”;
file<<“tutorial by muhammad ahsan”;

file.close();
cout<<“new check your file ahsan.txt which is successfully created in your directory \n the text which is written in your text file is already in c++ code.”;
}
return 0;
}

 

113

 

 

 

Student Management information System

aq

#include<iostream>
#include<conio.h>
#include<windows.h>
#include<string.h>

using namespace std;

class link
{
private:

int b,x,i,choice,n,a;
char cont;

struct node
{
int data;
string name;
string email;
string home;
string off;
string tell;
string cell;
string sec;
string gender;
struct node *link;

}head,temp,temp1,temp2;

public:
link()
{

head=NULL;
}

void start()
{
Sleep(800);
gotoxy(20,10); // if you want to change to postion of the bottom line x-axis and y-axis
cout<<“EVENT REGISTERED MANAGMENT INFORMATION SYSTEM\n”;
Sleep(600);
system(“color 0”); // change first loading font color
gotoxy(20,11); // if you want to change to postion of the loading line x-axis and y-axis
Sleep( 1000 );
cout<<“\xDB\xDB\xDB\xDB”;
Sleep(2000);
cout<<“\xDB\xDB\xDB”;
Sleep(1000);
cout<<“\xDB\xDB\xDB”;
Sleep(1000);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\xDB\xDB\xDB\xDB\xDB”;
Sleep(500);
cout<<“\n\n\n Welcome to the Application 2015 “;
Sleep(1500);

system(“color 3”); // change first loadiing background color
effect();
main_menu();
}

void main_menu()
{

do
{
system(“cls”);
cout<<“\n\t\t\t\t\t\tMAIN MENU \n”<<endl<<endl;
cout<<“\t_________________________________________________________”;

cout<<“\n\t\t1.Add Record “;
cout<<“\t\t2.Delete Specify Record”<<endl;
cout<<“\t_________________________________________________________”;

cout<<“\n\t\t3.Delete All Records”;
cout<<“\t4.Find A Record”<<endl;
cout<<“\t_________________________________________________________”;

cout<<“\n\t\t5.Display All Records”;
cout<<“\t6.About Developer”<<endl;
cout<<“\t_________________________________________________________”;
cout<<“\t\t\t\t7.Exit”<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<“||Choose option : “;
choice=getche();
switch(choice)
{
case ‘1’:
system(“cls”);
insert();
break;
case ‘2’:
system(“cls”);
del_specify();
break;
case ‘3’:
system(“cls”);
del();
break;
case ‘4’:
system(“cls”);
search();
break;
case ‘5’:
system(“cls”);
print();
break;
case ‘6’:
About_Dev();
break;
case ‘7’:
exit(0);
break;
default:
cout<<“\nInvalid Key Pressed……………..”;
}

cout<<“\n\nPress ENTER KEY To <continue>”;
cout<<“\n\n
Press ESC KEY To <exit>”;

x=getche();
system(“cls”);
if(x==27)
{
exit(0);
}

else
{
main_menu();
}
}while(x==13);

}

void About_Dev()
{
effect();
system(“cls”);
cout<<“\n”;
gotoxy(45,1);
cout<<“\xDB\xDB\xDB\xDB\xDB\xDB About Developer \xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\n\n”;
gotoxy(45,3);cout<<“\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB All Rights Reserved \xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\n”;
Sleep(1000);cout<<“\nCoder Name : M.”;Sleep(1000);cout<<“Muhammad”;Sleep(1000);cout<<” Ahsen\n”;Sleep(2000);
cout<<“\nProject Developed On : 2nd Dec 2015\n”;Sleep(3000);
cout<<“\nPlatform :Visual Studio 2015 \n”;Sleep(2000);
cout<<“\nLanguage :C++\n”;Sleep(1000);
cout<<“\nDataBase : \n1)Event Registration Management System \n”;Sleep(2000);
Sleep(1000); //sleep – suspend execution for an interval of time
cout<<“\n\n\n\tSomeone Tries To Copy/Paste Will Be Punished Quite Badly That He Would Have Never Dreamed \n\n “;Sleep(8000);

}
void insert(void)
{
effect();

char get1[100],get2[100],get3[100],get4[100],get5[100],get6[100],get7[100],get8[100];
gotoxy(45,1);cout<<” Add Record \n”;
gotoxy(45,2);cout<<” ___________\n”;
cout<<“\n”;

if(head==NULL)
{

head =new struct node;
i=1;
cout<<“\n# Student Id:”<<i<<endl;
head->data=i;
fflush(stdin);
cout<<“\n# Name :” ;
gets(get1);
head->name=get1;
cout<<“\n# Class : “;
gets(get6);
head->off=get6;
cout<<“\n# Section : “;
gets(get7);
head->sec=get7;
cout<<“\n# Gender : “;
gets(get8);
head->gender=get8;
cout<<“\n# Enter student home Number : “;
gets(get2);
head->tell=get2;
cout<<“\n# Enter student mobile Number : “;
gets(get3);
head->cell=get3;
cout<<“\n# Enter student Email Address : “;
gets(get4);
head->email=get4;
cout<<“\n# Challange : “;
gets(get5);
head->home=get5;
head->link=NULL;
cout<<“\n Record Has been Success Fully registered \n”;
}
else
{
temp=head;
head=new struct node;
i++;
cout<<“\n# Student Id:”<<i<<endl;
head->data=i;
fflush(stdin);
cout<<“\n# Name :” ;
gets(get1);
head->name=get1;
cout<<“\n# Class : “;
gets(get6);
head->off=get6;
cout<<“\n# Section : “;
gets(get7);
head->sec=get7;
cout<<“\n# Gender : “;
gets(get8);
head->gender=get8;
cout<<“\n# Enter Telephone Number : “;
gets(get2);
head->tell=get2;
cout<<“\n# Enter Cell-Phone Number : “;
gets(get3);
head->cell=get3;
cout<<“\n# Enter Email Address : “;
gets(get4);
head->email=get4;
cout<<“\n# Enter chalange : “;
gets(get5);
head->home=get5;
head->link=temp;
cout<<“\nYour Record Has been SuccessFully inserted\n”;
}
cout<<“\nDo You Want To Add Another Record ? y / n \a”;
cont=getche();
if(cont==’y’)
{
cout<<“\n”;
system(“cls”);
insert();
}

Sleep(1000);
main_menu();

}

void search(void)
{
effect();
system(“cls”);
temp=head;

cout<<“\n\n\t\t\t\t\t\t\aRestriction!\n\n\n\n\t\t\t\t Student ID should be in integer not in char “;
Sleep(3000);
system(“cls”);
cout<<“\nEnter Id Which do you want to search:”;

cin>>a;
fflush(stdin);
while(head!=NULL)
{

if(head->data==a)
{
cout<<“\n”;
gotoxy(45,1); cout<<“Entry Found\n”;
gotoxy(45,2); cout<<” ____________\n”;
cout<<“==========================================================================================================================”;
cout<<“\n”;
cout<<“\n# ID: “<<head-> data;
cout<<“\n# Name: “<<head-> name;
cout<<“\n# Class : “<<head -> off;
cout<<“\n# Section : “<<head ->sec;
cout<<“\n# Gender : “<<head ->gender;
cout<<“\n# Telephone Number : “<<head-> tell;

cout<<“\n# Cell-Phone Number : “<<head -> cell;
cout<<“\n# Email Address : “<<head -> email;

cout<<“\n# Challange : “<<head-> home;

cout<<“\n”;
cout<<“===========================================================================================================================”;

return;

}
else

{
head=head->link;
}
}
cout<<“Not found”;
}

void del(void)
{
while(head!=NULL)
{
delete(head);
head=head->link;

}
cout<<“\nYour all record has been deleted….”;

}

void print(void)
{
effect();

temp1=head;
if(temp1==NULL)
{

cout<<“No Entries Found…..”;
Sleep(1000);
main_menu();

}

x:
system(“cls”);
gotoxy(45,1);cout<<“Display Record \n”;
cout<<“=====================================================================================================================”;
cout<<“\n”;
cout<<“\n# ID: “<<temp1-> data<<endl;
cout<<“\n# Name: “<<temp1-> name<<endl;
cout<<“\n# Class : “<<temp1 -> off<<endl;
cout<<“\n# Section : “<<temp1 ->sec<<endl;
cout<<“\n# Gender : “<<temp1->gender<<endl;
cout<<“\n# Telephone Number : “<<temp1-> tell<<endl;
cout<<“\n# Cell-Phone Number : “<<temp1 -> cell<<endl;
cout<<“\n# Email Address : “<<temp1 -> email<<endl;
cout<<“\n# HChallange : “<<temp1-> home<<endl;
cout<<“\n”;
cout<<“=======================================================================================================================”;
cout<<“\n”;
cout<<“\nDo You Want To View Another Record ? y / n \a”;
cont=getche();

if(cont==’y’)
{

cout<<“\n”;

if(temp1->link==NULL)
{
cout<<“\nNo More Entries ……..”;
Sleep(1000);
main_menu();
}
temp1=temp1->link;

goto x;

}

else if(temp1->link==NULL)
{
cout<<“\nNo More Entries ……..”;
Sleep(1000);

main_menu();

}

else
{
main_menu();
exit(0);
}

}

void del_specify(void)

{
effect();
system (“cls”);
cout<<“\n\t\t\t Delete A Record \n”;
cout<<“\n\t\t\t ________________\n”;
cout<<“Enter Id which you want to del:”;
cin>>n;

if(head->data==n)
{

free(head);

head=head->link;
cout<<“\n”;
cout<<n<<” is successfully deleted in node”;
}
else
{
delete_node(n);
}

}

void delete_node(int n)
{
effect();

temp1 = head;
temp2 = head;

while (temp1 != NULL)
{
if (temp1->data == n)
{

break;
}

if (temp1 == temp2)
{
temp1 = temp1->link;
}
else
{

temp2 = temp2->link;
temp1= temp2->link;
}}

if (temp1 == NULL){
cout << “ID not found” << endl;

}
else
{

temp2 -> link = temp2 ->link->link;
delete temp1;
cout<<“\n”;
cout<<n<<” is successfully deleted in node”;

}

}

void gotoxy(int x, int y)
{
COORD ord;
ord.X = x;
ord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), ord);
}

void effect()
{ int i,j;
char ch;
ch=220;
gotoxy(0,0);
for (i=0;i<25;i++)
{
for(j=0;j<125;j++)
{
cout<<ch;

}
Sleep(12);

cout<<“\n”;
}
gotoxy(0,0);
for (i=0;i<27;i++)
{
cout<<“\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \n”;
Sleep(20);
}
}
};

int main()
{
link obj;
obj.start();
getch();
}


 

Bank Management Information System

bank

#include<iostream>
#include<fstream>
#include<cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::ofstream;
using std::ifstream;
using std::ios;
class account_query
{
private:
char account_number[20];
char firstName[10];
char lastName[10];
float total_Balance;
public:
void read_data();
void show_data();
void write_rec();
void read_rec();
void search_rec();
void edit_rec();
void delete_rec();
};
void account_query::read_data()
{
cout<<“\nEnter Account Number: “;
cin>>account_number;
cout<<“Enter First Name: “;
cin>>firstName;
cout<<“Enter Last Name: “;
cin>>lastName;
cout<<“Enter Balance: “;
cin>>total_Balance;
cout<<endl;
}
void account_query::show_data()
{
cout<<“Account Number: “<<account_number<<endl;
cout<<“First Name: “<<firstName<<endl;
cout<<“Last Name: “<<lastName<<endl;
cout<<“Current Balance: Rs. “<<total_Balance<<endl;
cout<<“——————————-“<<endl;
}
void account_query::write_rec()
{
ofstream outfile;
outfile.open(“record.bank”, ios::binary|ios::app);
read_data();
outfile.write(reinterpret_cast<char >(this), sizeof(this));
outfile.close();
}
void account_query::read_rec()
{
ifstream infile;
infile.open(“record.bank”, ios::binary);
if(!infile)
{
cout<<“Error in Opening! File Not Found!!”<<endl;
return;
}
cout<<“\n****Data from file****”<<endl;
while(!infile.eof())
{
if(infile.read(reinterpret_cast<char>(this), sizeof(this))>0)
{
show_data();
}
}
infile.close();
}
void account_query::search_rec()
{
int n;
ifstream infile;
infile.open(“record.bank”, ios::binary);
if(!infile)
{
cout<<“\nError in opening! File Not Found!!”<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(this);
cout<<“\n There are “<<count<<” record in the file”;
cout<<“\n Enter Record Number to Search: “;
cin>>n;
infile.seekg((n-1)
sizeof(this));
infile.read(reinterpret_cast<char
>(this), sizeof(this));
show_data();
}
void account_query::edit_rec()
{
int n;
fstream iofile;
iofile.open(“record.bank”, ios::in|ios::binary);
if(!iofile)
{
cout<<“\nError in opening! File Not Found!!”<<endl;
return;
}
iofile.seekg(0, ios::end);
int count = iofile.tellg()/sizeof(
this);
cout<<“\n There are “<<count<<” record in the file”;
cout<<“\n Enter Record Number to edit: “;
cin>>n;
iofile.seekg((n-1)sizeof(this));
iofile.read(reinterpret_cast<char>(this), sizeof(this));
cout<<“Record “<<n<<” has following data”<<endl;
show_data();
iofile.close();
iofile.open(“record.bank”, ios::out|ios::in|ios::binary);
iofile.seekp((n-1)sizeof(this));
cout<<“\nEnter data to Modify “<<endl;
read_data();
iofile.write(reinterpret_cast<char>(this), sizeof(this));
}
void account_query::delete_rec()
{
int n;
ifstream infile;
infile.open(“record.bank”, ios::binary);
if(!infile)
{
cout<<“\nError in opening! File Not Found!!”<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(this);
cout<<“\n There are “<<count<<” record in the file”;
cout<<“\n Enter Record Number to Delete: “;
cin>>n;
fstream tmpfile;
tmpfile.open(“tmpfile.bank”, ios::out|ios::binary);
infile.seekg(0);
for(int i=0; i<count; i++)
{
infile.read(reinterpret_cast<char
>(this),sizeof(this));
if(i==(n-1))
continue;
tmpfile.write(reinterpret_cast<char
>(this), sizeof(*this));
}
infile.close();
tmpfile.close();
remove(“record.bank”);
rename(“tmpfile.bank”, “record.bank”);
}
int main()
{
account_query A;
int choice;
cout<<“***Acount Information System***”<<endl;
while(true)
{
cout<<“Select one option below “;
cout<<“\n\t1–>Add record to file”;
cout<<“\n\t2–>Show record from file”;
cout<<“\n\t3–>Search Record from file”;
cout<<“\n\t4–>Update Record”;
cout<<“\n\t5–>Delete Record”;
cout<<“\n\t6–>Quit”;
cout<<“\nEnter your choice: “;
cin>>choice;
switch(choice)
{
case 1:
A.write_rec();
break;
case 2:
A.read_rec();
break;
case 3:
A.search_rec();
break;
case 4:
A.edit_rec();
break;
case 5:
A.delete_rec();
break;
case 6:
exit(0);
break;
default:
cout<<“\nEnter corret choice”;
exit(0);
}
}
system(“pause”);
return 0;
}


Friend Function  in C++:

/* C++ program to demonstrate the working of friend function.*/
#include <iostream>
using namespace std;
class Distance
{
    private:
        int meter;
    public:
        Distance(): meter(0){ }
        friend int func(Distance);  //friend function
};
int func(Distance d)            //function definition
{
    d.meter=5;         //accessing private data from non-member function
    return d.meter;
}
int main()
{
    Distance D;
    cout<<"Distace: "<<func(D);
    return 0;
}

 

 

 

 

 

 

 

 

 

 

 

 

Advertisements