Monday, 13 April 2020

Program : star sequence program

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf(“*”);
printf(“\n”);
}
getch();
}

Program: Menu driven program in java

Write a menu driven program to generate the upper case letters from Z to A and lower case letters from 'a' to 'z' as per the user's choice. Enter '1' to display upper case letters from Z to A and Enter '2' to display lower case letters from a to z.


import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter '1' to display upper case letters from Z to A");
System.out.println("Enter '2' to display lower case letters from a to z");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
int count = 0;
switch (ch)
{
case 1: for (int i = 90; i > 64; i--)
{
char c = (char)i; System.out.print(c);
               
}
break;
case 2: for (int i = 97; i < 123; i++)
{
char c = (char)i; System.out.print(c);           
}
break;
default: System.out.println("Incorrect Choice");
        }   
}
}

Write a program to maintain the records of person with details (Name and Age) and find the eldest among them.

Write a program to maintain the records of person with details (Name and Age) and find the eldest among them. The program must use this pointer to return the result. 



#include<iostream.h>
#include<string.h>
class person
{ 
char name[20]; 
float age;
public: 
person(char *s, float a) 
{ 
strcpy(name, s); 
age = a; 
}
person & person :: greater(person & x) 
{ 
if(x.age >= age)   
return x; 
else   
return *this; 
}
void display(void) 
{ 
cout<<"Name:"<<name<<"\n"    <<"Age: "<<age<<"\n"; 
}
};
int main()
{ 
person p1("John", 37.50),     
p2("Ahmed",29.0),     
p3("Hebber", 40.5);
person p = p1.greater (p3); 
cout<<"Elder Person is:\n"; 
p.display();
p = p1.greater (p2); 
cout<<"Elder Person is:\n"; 
p.display();
return 0;
}

Sunday, 12 April 2020

Program: write a program to display input year is leap year or not

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“enter any year: ”);
scanf(“%d”,&n);
if(n%4==0)
printf(“year is a leap year”);
else
printf(“year is not a leap year”);
getch();
}

Program : use of file in C++

Write a program to implement I/O operations on characters. I/O operations includes inputing a string, Calculating length of the string, Storing the String in a file, fetching the stored characters from it, etc.



#include<iostream.h>
#include<fstream.h>
#include<string.h>
int main()
{ 
char string[80]; 
cout<<"Enter a String \n"; 
cin>>string; 
int len = strlen(string);
fstream file; 
file.open("TEXT", ios::in | ios::out);
for(int i=0;i<len;i++) 
file.put(string[i]);
file.seekg(0);
char ch; 
while(file) 
{ 
file.get(ch); 
cout<<ch; 
} 
return 0;
}