Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
181 views

Output Assignment

The document contains 31 code snippets from a computer science output assignment. The snippets cover a range of programming concepts like loops, functions, arrays, structures, pointers and more. The code demonstrates techniques like string manipulation, character conversion, parameter passing, structure handling and more.

Uploaded by

chins1289
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views

Output Assignment

The document contains 31 code snippets from a computer science output assignment. The snippets cover a range of programming concepts like loops, functions, arrays, structures, pointers and more. The code demonstrates techniques like string manipulation, character conversion, parameter passing, structure handling and more.

Uploaded by

chins1289
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DELHI PUBLIC SCHOOL, GANDHINAGAR

COMPUTER SCIENCE
OUTPUT ASSIGNMENT CLASS XI

1. void main( )
{ char NAME[] =a ProFiLe
for (int x = 0 ; x < strlen (NAME) ; x++)
if (islower(NAME[x]) )
NAME[x] = toupper (NAME[x] );
else if (isupper(NAME[x]) )
if (x%2 ! =0)
NAME [x] = tolower (NAME[x-1] ) ;
else
NAME[x] - - ;
cout < < Name < < endl ;
}

2. int func (int & x, int y = 10)
{ if (x % y == 0)
return ++x ;
else
return y --;
}
void main ( )
{ int p = 20, q = 23;
q = func (p,q);
cout < < p < < endl;
p = func (q) ;
cout < < p < < q < < endl ;
q = func (p) ;
cout < < p < < q < < endl ;
}

3. void main( )
{ char s[ ]= GOODLUCK;
for ( int x = strlen (s) - 1; x >= 0; x--)
{ for (int y = 0; y <= x; y++)
cout< <s[y];
cout < < endl;
}
}
4. int a = 3;
void demo (int x, int y, int & z)
{ a += x + y;
z = a + y;
y += x;
cout < < x < < y < <z < < endl;
}
void main ( )
{ int a = 2, b = 5;
demo (::a, a, b );
cout < < :: a < < a < < b < < endl;
demo ( ::a, a, b );
}
5. void main( )
{ char NAME[ ] = IntRAneT ;
for (int x = 0 ; x < strien(name) ; x++)
if( islower(NAME[x]) )
NAME[x] = toupper(NAME[x]) ;
else if (isupper(NAME[x])
if (x % 2 == 0)
NAME[x] = tolower(NAME[x]);
else
Name[x] = NAME[x-1] ;
puts(NAME) ;
}

6. void Execute (int & X, int Y = 200)
{ int TEMP = X + Y ;
X += TEMP ;
If (Y != 200)
cout < < TEMP < < X < < Y < < endl;
}
void main( )
{ int A = 50, B = 20 ;
Execute (B) ;
cout < < A < <B < < endl;
Execute (A,B) ;
}

7. void main( )
{ char NAME[ ] = CoMPutER ;
for ( int x = 0; x <strlen(NAME) ; X+ +)
if(islower(NAME[x]) )
NAME[x] = toupper(NAME[x]) ;
else if ( isupper(NAME[x]) )
if (x % 2 = =0)
NAME[x] = tolower(NAME[x]) ;
else
NAME[x] = NAME[x 1 ] ;
puts(name);
}

8. void Execute ( int & B, int C = 100)
{ int TEMP = B + C ;
B + = TEMP ;
if ( C = = 100)
cout < < TEMP < < B < < C < < endl;
}
void main ( )
{ int M = 90, N = 10 ;
Execute (M) ;
cout < < M < < N < < endl;
Execute ( M, N) ;
cout < < M < < N < < endl;
}

9. void main()
{ for(int I = 1; I <= 5; I++)
{ cout << endl;
for(int j =0; j <= I; j++)
cout << * <<\t;
}
}

10. int global = 10;
void func(int & X, int Y)
{ X = X Y;
Y = X * 10;
cout < < X < < , < < Y < < \n ;
}
void main()
{ int global = 7;
func(:: global,global) ;
cout < < global < < , < <:: global < < \n ;
func(global, ::global) ;
cout < < global < < , << :: global < < \n ;
}




11. int a = 10;
void demo (int &x, int y, int *z)
{ a += x;
y *= a;
*z = a + y;
cout < < x < < y < <*z < < endl;
}
void main ( )
{ int a = 20, b = 5;
demo (::a, a, &b );
cout < < :: a < < a < < b < < endl;
}
12. int & max(int &x, int &y)
{ if(x > y)
return (x);
else
return (y);
}
void main()
{ int a = 10, b = 13;
max(a, b) = -1;
cout << a = <<a<< b = <<b<<endl;
max(b, a) = 7;
cout << a = <<a++<< b = <<b++<<endl;
max(a, b) = 3;
cout << a = <<a<< b = <<b<<endl;
}
13. void change(int b[5])
{ for(int I=0; I<=4; I++)
{ b[I] = b[I] + 1;
}
}
void main()
{ int a[5] = {4, 5, 6, 7, 8};
change(a);
for(int I=4; I>=0; I--)
cout << a[I];
}
14. void swap(int I, int j)
{ int temp = I; I = j; j = temp; }
void main()
{ int a= 5, b = 4;
swap(a, b);
cout << a = << a << and b = <<b;
}

15. void metal(int temp, int &m, int n = 10)
{ m = temp + n; n = m 29; temp++;
cout << temp << m << n << endl;
}
void main()
{ int x = 100, y = 200;
metal(x, y);
cout << x << y << endl;
metal(2*x, x);
cout << x << y << endl;
}

16. int max (int & x, int & y, int & z)
{ if (x > y && y > z)
{ y++; z++;
return x;
}
else if (y > x) return y;
else return z;
}
void main()
{ int a = 10, b = 13, c = 8;
a = max(a,b,c);
cout <<a<<b<<c<<endl;
b = max(a,b,c);
cout <<++a<<++b<<++c<<endl;
c = max(a,b,c);
cout <<a++<<++b<<+++c<<endl;
}

17. void main ()
{ int x = 5, y =5;
cout <<x++;
cout <<, ;
cout <<++x;
cout <<, ;
cout <<y++<<,<<++y;
}


18. void X(int A, int & B)
{ A = A+B; B = A B; A = A B; }
void main ()
{ int a = 4, b = 18;
X (a,b);
cout <<a <<,<<b;
}

19. void main();
{ int x = 5, y = 5;
cout << x--;
cout << , ;
cout << --x;
cout << , ;
cout << y-- << , << --y;
}

20. int Calc (int U)
{ if (U%2 ==0)
return U + 10;
else
return U * 2;
}
void pattern (char M, int B = 2)
{ for (int CNT = 0; CNT < B; CNT++) cout<<Calc(CNT)<<M;
cout << endl;
}
void main()
{
pattern(*); pattern(#,4); pattern(@,3);
}

21. int Execute(int M)
{ if(M % 3 == 0) return M * 3;
else return M+10;
}
void output(int B = 2)
{ for(int T=0; T < B; T++)
cout << Execute(T) << *;
cout << endl;
}
void main()
{ output(4);
output( );
output(3);
}

22. void Change(char Msg[ ], int Len)
{ for(int count = 0; count < Len; count++)
{ if(islower(Msg[count]))
Msg[count] = toupper(Msg[count]);
else if(isupper(Msg[count]))
Msg[count] = tolower(Msg[count]);
else if(isdigit[Msg[count]))
Msg[count] = Msg[count] + 1;
Else
Msg[count] = ;
}
}
void main( )
{ char Message[ ] = 2014 Tests ahead;
int Size = strlen(Message);
Change(Message, Size);
cout << Message << endl;
for(int C = 0, R = Size 1; C <= Size / 2; C++, R--)
{ char Temp = Message[C];
Message[C] = Message[R];
Message[R] = Temp;
}
cout << Message << endl;
}

23. void main( )
{ long Number = 7583241;
int First = 0, Second = 0;
do
{ int R = Number % 10;
if(R % 2 == 0)
First += R;
else
Second += R;
Number /= 10;
}while(Number > 0);
cout << First_Second;
}

24. void indirect(int Temp = 20)
{ for(int x = 10; x <= Temp; x += 5)
cout << x << ,;
cout << endl;
}
void direct(int &Num)
{ Num += 10;
indirect(Num);
}
void main( )
{ int Number = 20;
direct(Number)
indirect( );
cout << Number = << Number << endl;
}

25. void main( )
{ int a = 5, b = 10;
for(int x = 1; x <= 2; x++)
{ cout << Line 1 << a++ << & << b 2 << endl;
cout << Line 2 << ++b << & << a + 3 << endl;
}
}



26. void main( )
{ char Mystring[ ] = What@OUTPUT!;
for(int x = 0; Mystring[x] != \0; x++)
{ if(!isalpha(Mystring[x]))
Mystring[x] = *;
else if(isupper(Mystring[x]))
Mystring[x] = Mystring[x] + 1;
else
Mystring[x] = Mystring[x + 1];
}
cout << Mystring;
}

27. void main( )
{ int A[ ] = {10,15,20,25,30};
int p=0;
while(A[p] < 30)
{ if(A[p] % 3 != 0)
A[p] = A[p] + 2;
else
A[p] = A[p] + 1;
p++;
}
for(int J = 0; J <= 4; J++)
{ cout << A[J] << *;
if(J % 3 == 0) cout << endl;
}
cout << A[4] * 3 << endl;
}
28. void Secret(char Msg[ ], int N)
{ for(int C = 0; Msg[C] != \0; C++)
if(C % 2 == 0)
Msg[C] = Msg[C] + N;
else if(isupper(Msg[C]))
Msg[C} = tolower(Msg[C]);
else
Msg[C} = Msg[C] 1;
}
void main( )
{ char SMS[ ] = rEPorTmE;
Secret(SMS,2);
cout << SMS << endl;
}

29. struct point
{ int X, Y ; };
void show (point P)
{ cout <<P. X << ; << P . Y << endl; }
void main ()
{ point U = { 20 , 10 } , V , W ;
V = U; V . X + = 20;
W = V;
U .Y + = 10; U . X + = 5;
W . X - = 5;
show (U); show (V); show (W);
}

30. struct THREE_D
{ int X, Y, Z; };
void MOVEIN(THREE_D &T, int Step = 1)
{ T.X += Step; T.Y = Step; T.Z += Step:
}
void MOVEOUT(THREE_D &T, int Step = 1)
{ T.X = Step; T.Y += Step; T.Z = Step;
}

void main( )
{ THREE_D T1 = {10, 20, 5}, T2 = {30, 10, 40};
MOVEIN(T1);
MOVEOUT(T2, 5);
cout << T1.X << , << T1.Y << , << T1.Z << endl;
cout << T2.X << , << T2.Y << , << T2.Z << endl;
MOVEIN(T2, 10);
cout << T2.X << , << T2.Y << , << T2.Z << endl;
}

31. void mycode(char msg[ ], char ch)
{ for(int c = 0, msg[c] != \0, c++)
{ if(msg[c] >= B && msg[c] <= G) msg[c] = tolower(msg[c]);
else if(msg[c] == A || msg[c] == a) msg[c] = ch;
else if(c % 2 == 0) msg[c] = toupper(msg[c]);
else msg[c] = msg[c 1];
}
}
void main( )
{ char mytext[ ] = ApEACeDriVE;
mycode(mytext, @); cout << NEW TEXT : <<mytext<<endl;
}

32. void switchover(int A[ ], int N, int split)
{ for(int k = 0; k < N; k++)
if(k < split) A[k] += k;
else A[k] *= k;
}
void display(int A[ ], int N)
{ for(int k = 0; k < N; k++)
(k % 2 == 0) ? cout << A[k] << % : cout << A[k] << endl;
}
void main( )
{ int H[ ] = {30, 40, 50, 20, 10, 5};
switchover(H, 6, 3); display(H, 6);
}

33. #include <stdio.h>
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++) {result += array1[temp];
}
for (temp = 0; temp < 4; temp++) { result += array2[temp]; }
cout << result;
return 0;
}

34. int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0 ;n < 5 ;n++) { result += billy[n]; }
cout << result;
return 0;
}








35. void main()
{ char Mes1[ ] = SKy, Mes2[ ] = ThE, Mes3[ ] = LiMIT;
int L1 = strlen(Mes1), L2 = strlen(Mes2), L3 = strlen(Mes3);
int N = L1 + L2 + L3;
for(int c = 0; c < N; c++)
{ if(c % 4 == 0)
{ cout << Mes2[L2-1]; L2--;
}
else if(c % 3 == 0)
{ cout << Mes1[L1-1] << endl; L1--;
}
else
{ cout << Mes3[L3-1]; L3--;
}
}
}

36. struct Pixel
{ int C, R;
};
void display(Pixel P)
{ cout << Col<<P.C<<Row<<P.R<<endl;
}
void main()
{ Pixel x = {40, 50}, y, z;
z = x;
x.C += 10;
y = z;
y.C += 10;
y.R += 20;
z. C = 15;
display(x);
display(y);
display(z);
}

37. # include <iostream.h>
int i=20;
void main()
{
int i=7;
cout<< i<< << : : I << endl;
}

38. #include <iostream.h>
void main( )
{ int i = 0, x = 0;
do
{ if(i % 5 = = 0)
{ cout<<x;
x++;
}
++ i;
}while(i<10);
cout<<\n<<x;
}


39. void main()
{ int x = 5;
if(x++ = = 5)
cout<<five<<endl;
else
if(++x = = 6)
cout<<Six<<endl;
}

40. struct number
{
int no1, no2;
};
void display(number n)
{
cout<<Number1=<<n.no1++<<Number2=<< - -n.no2<<endl;
}
void main( )
{
number n1={10,100}, n2, n3;
n3 = n1;
n1.no1 + = 5;
n2 = n3;
n2.no1 - = 5;
n2.no2 * = 2;
n3.no1 + = 1;
display(n1);
display(n2);
display(n3);
}
41. void display(char nm[])
{
char ch=nm[0];
for(int i=0;i<strlen(nm);++i)
{
nm[i]=nm[i+1];
}
nm[i]=ch;
cout<<nm;
}
void main()
{
char title[20]={COMPUTER};
display(title);
cout<<title;
}

42. #include<iostream.h>
#inlucde<ctype.h>
typedef char Str80[80]
void main( )
{
Str80 Str= vR2GooD;
int L=6;
while(L >=3)
{ Str[L] = (isupper(Str[L]) ? tolower(Str[L]) : toupper(Str[L]));
L - -;
cout << Str[L];
}
}
43. #include <iostream.h>
#include<stdio.h>
#include<string.h>
void main()
{
char Mes1[]=Sky,Mes2[]=ThE,Mes3[]=LiMIT;
int L1=strlen(Mes1),L2=strlen(Mes2),L3=strlen(Mes3);
int N=L1+L2+L3;
for(int c=0;c<N;c++)
{
if(c%4==0)
{
cout<Mes2[L2-1];
L2--;
}
else
if(c%3==0)
{
cout<<Mes1[L1-1]<<endl;
L1--;
}else
{
cout<<Mes3[L3-1];
L3--;
}

43. void main()
{
int a,b=0;
int c[10]={1,2,3,4,5,6,7,8,9,10};
for(a=0;a<10;++a)
if((a%2)==0 b+=c[a];
cout<<b;
}
44. #include<iostream.h>
void main()
{
int i=4
int a;
A=add(i);
cout<<a;
}
int add(int j)
{
if(j>=4) j=j*j;
else j=j*2;
return(j);
}

45 int sum (int arr[], int size);
int main()
{
int val[]={3,5,2,6,7,8,9,2,4,22}, s1,s2,s3;
s1=sum(val,10);
s2=sum(val+3,6);
s3=sum(val+2,10-2);
cout<<"s1="<<s1<<endl<<"s2="<<s2<<endl<<"s3="<<s3;
return 0;
}
int sum(int arr[],int size)
{
for(int i=0,s=0;i<size;++i)
s+=arr[i];
return s;
}

You might also like