PRACTCE LAB OOP C++ PROGRAMING by zuhaibriaz

VIEWS: 16 PAGES: 7

More Info
									1-

# include <iostream.h>

# include <stdlib.h>

int s (int* , int*);

main(){

int x[10];

int a,b,t;

for (int i=0; i<10; i++)

{

cout<<"Enter Number at position "<<i<<'\t';

cin>>x[i];

}cout<<"\n\nHere are the sorted numbers\n\n";

for(a=0; a<10; a++)

{

for(b=0; b<10; b++)

{

if (x[b]>x[b+1])

{

s (&x[b],&x[b+1]);

}

    }



cout<<'\t';

for (b=0; b<10; b++)

{
cout<<x[b]<<" ";

}

cout<<'\n'<<'\n';

if (s == 0)

break;



}

system("PAUSE");

}



int s (int*x,int*y)

{

int t;



t = *x;

*x = *y;

*y = t;}

2-

# include <iostream.h>

# include <ctype.h>

# include <stdlib.h>

void u (char *);

main()

{

char a[30]="welcome to leads university";
cout<<"The string before conversion is: \t"<<a<<'\n';

cout<<"\nNow it will be converted to upper case\n\n";

u (a);

cout<<"The string before conversion is: \t"<<a<<'\n';



system("PAUSE");

}



void u (char*r)

{

while (*r!='\0')

{

if (islower(*r))



*r = toupper(*r);

r++;



    }

}
3-

/* This program uses array manipulation using indexing */

#include <iostream.h>

#include <stdlib.h>

void main(void)

{

     int c[5], v[10];

     int multi [5][10];

     int *ptr;              // A normal 'int' pointer

     ptr = *multi;          // 'ptr' is assigned the starting address of the first row



     /* Initialize the array elements */

     for(int i=0; i < 6; i++)

     {

         for (int j=0; j < 10; j++)

         {

              multi[i][j] = i * j;

         }

     }



     /* Array manipulation using indexing */

     cout << "\n Array manipulated using indexing is: \n";

     for(int i=2; i <6; i++)

     {

         for (int j=1; j < 10; j++)
        {

            cout << multi[i][j] << '\t';

        }

        cout << '\n';

    }



    //Array manipulation using pointer

    cout << "\n Array manipulated using pointer is: \n";

    for(int k=0; k < 50; k++, ptr ++)      // 5 * 10 = 50

    {

        cout << *ptr << '\t';

    }




system("PAUSE");

}




4
# include <iostream.h>

# include <ctype.h>

# include <stdlib.h>



void u (char *);



main()

{



char a[30]="WELCOME TO Leads University";

cout<<"The string before conversion is: \t"<<a<<'\n';

cout<<"\nNow it will be converted to upper case\n\n";

u (a);

cout<<"The string before conversion is: \t"<<a<<'\n';



system("PAUSE");

}



void u (char*r)

{

while (*r!='\0')

{

if (isupper(*r))



*r = tolower(*r);
r++;



    }

}

								
To top