Tuesday, 21 April 2020

File Management part-2

HTML tags for Graphics and Tables

Program to shift input data by two bits to the left.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf(“Read the integer from keyboard :- ”);
scanf(“%d”,&x);
x<<=3;
y=x;
printf(“\nThe left shifted data is = %d ”,y);
getch();
}

Write a program to input a letter. Find its ASCII code. Reverse the ASCII code and display the equivalent character.

Sample Input: Y
Sample Output: ASCII Code = 89
 Reverse the code = 98
 Equivalent character: b



public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a letter: ");
char l = in.next().charAt(0);
int a = (int)l;
System.out.println("ASCII Code = " + a);
int r = 0;
while (a > 0)
{
int digit = a % 10;           
r = r * 10 + digit;           
a /= 10;       
}
System.out.println("Reversed Code = " + r);
System.out.println("Equivalent character = " + (char)r);
    }
}

Write a program in C++ to highlight the difference between overloaded assignment operator and copy constructor.

#include<iostream.h>
class circle
{
private:   
int   radius;   
float x, y;
public:   
circle( ){     }   
circle( int  rr, float  xx, float  yy )   
{       
radius = rr;       
x = xx;       
y = yy;   
}   
circle  operator =( circle & c )   
{       
cout << endl << "Assignment operator invoked";       
radiius = c.radius;       
x= c.x;       
y= c.y;       
return circle( radius, x, y );   
}   
circle( circle & c )
{       
cout << endl << "copy constructor invoked";       
radius = c.radius;       
x= c.x;       
y= c.y;   
}   
void showdata( )
{       
cout << endl << "Radius = " << radius;       
cout << endl << "X-Coordinate=" << x;       
cout << endl << "Y-Coordinate=" << y;   
}
};
void main( )
{   
circle  c1 ( 10, 2.5, 2.5 );   
circle  c2,c4;   
c4 = c2 = c1;   
circle  c3  = c1;   
c1.showdata( );   
c2.showdata( );   
c3.showdata( );   
c4.showdata( );
} 

Monday, 20 April 2020

Program to use switch statement. Display Monday to Sunday.

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter m for Monday\nt for Tuesday\nw for Wednesday\nh for Thursday\nf for Friday\ns for Saturday\nu for Sunday);
scanf(“%c”,&ch);
switch(ch)
{
case ‘m’:case ‘M’: printf(“monday”);
break;
case ‘t’:case ‘T’: printf(“tuesday”);
break;
case ‘w’:case ‘W’: printf(“wednesday”);
break;
case ‘h’:case ‘H’: printf(“thursday”);
break;
case ‘f ’:case ‘F’: printf(“friday”);
break;
case ‘s’:case ‘S’: printf(“saturday”);
break;
case ‘u’:case ‘U’: printf(“sunday”);
break;
default : printf(“wrong input”);
break;
}
getch();
}