Академический Документы
Профессиональный Документы
Культура Документы
#include<iostream.h>
#include<conio.h>
int main ()
{
int num;
cout << "Enter the number to be checked : ";
cin >> num;
if (num >= 0)
cout << num << " is a positive number.";
else
cout << num << " is a negative number.";
getch();
return 0;
}
Output:
2 Check the Entered Year is a Leap Year or Not
Aim : Write a Program to find the given year is leaf year or not.
#include<iostream.h>
#include<conio.h>
#include<string.h>
int main()
{
int year;
Output Screen:
3 String Manipulation
Aim : Write a Program to concatenate the two strings using C++.
#include<iostream.h>
#include<conio.h>
#include<string.h>
int main()
if (val==0)
else
strcpy(temp,s1);
strcat(temp,s2);
cout<<"String Concatenate is"<<temp;
getch();
return 0;
#include<iostream.h>
#include<conio.h>
void main()
int i,n;
clrscr();
cin>>n;
for(i=0;i<=n;i++)
cout<<i<<endl”;
getch();
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,sum;
sum=0;
clrscr();
}
6 Display Tables
void main()
{
int num, i, tab;
cout<<"Enter the Table number : ";
cin>>num;
cout<<"Table of "<<num<<" is \n\n";
for(i=1; i<=20; i++)
{
tab=num*i;
cout<<i<<" * "<<num<<" = "<<tab<<"\n";
}
getch();
}
7 Display N numbers using While Loops
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n;
i=0;
clrscr();
cout<<"Enter the Number to Display ";
cin>>n;
while(i<=n)
{
cout<<i<<"\n";
i=i+1;
}
getch();
}
8 Sum of N Numbers using While Loops
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,sum;
sum=0;
i=0;
clrscr();
cout<<"Enter the Number to Display: ";
cin>>n;
while(i<=n)
{
sum=sum+i;
i=i+1;
}
cout<<"Sum of the Input Number: "<<n<<"is :"<<sum;
getch();
}
9 Find the Biggest of Three Numbers
Aim : Write a Program to find the biggest of three numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int n1, n2, n3;
cout << "Enter the First Number: ";
cin >> n1;
cout<<endl;
}
11 Display Student Mark Using Class Program in C++
Aim : Write a Program to display Student Mark using Class Program in C++
#include<iostream.h>
#include<conio.h>
class student
{
public:
char name[100], regno [20];
int m1,m2,m3,m4,total,avg;
void printname()
{
cout<< "Enter the Student Name: ";
cin>>name;
cout<< "Enter the Student Register No: ";
cin>>regno;
cout<< "Enter the Tamil Mark: ";
cin>>m1;
cout<<"**************************************";
cout<<"\n"<<"Student Name is :"<<name;
cout<<"\n"<<"\n"<<"Student Register Number:"<<regno;
cout<<"\n"<<"\n"<<"********************************"<<"\n";
cout<< "Tamil Mark: "<<m1<<"\n";
cout<<"English Mark: "<<m2<<"\n";
cout<< "Math Mark: "<<m3<<"\n";
cout<<"History Mark: "<<m4<<"\n";
total=m1+m2+m3+m4;
cout<< "Total Mark is "<<total<<"\n";
avg=(m1+m2+m3+m4)/4;
cout<< " Average Mark is "<<avg;
}
};
void main()
{
student info;
info.printname();
getch();
}
12 Friend Function
Aim : Write a C++ program to display the Student Mark List using Friend Function.
#include<iostream.h>
#include<conio.h>
class friend_function
{
public:
friend void display();
};
void display()
{
char name[100], regno [20];
int m1,m2,m3,m4,total,avg;
cout<<"**************************************";
cout<<"\n"<<"Student Name is :"<<name;
cout<<"\n"<<"\n"<<"Student Register Number:"<<regno;
cout<<"\n"<<"\n"<<"********************************"<<"\n";
cout<< "Tamil Mark: "<<m1<<"\n";
cout<<"English Mark: "<<m2<<"\n";
cout<< "Math Mark: "<<m3<<"\n";
cout<<"History Mark: "<<m4<<"\n";
total=m1+m2+m3+m4;
cout<< "Total Mark is "<<total<<"\n";
avg=(m1+m2+m3+m4)/4;
cout<< " Average Mark is "<<avg;
void main()
{
friend_function f;
display();
getch();
}
13 Constructor
#include<iostream.h>
#include<conio.h>
class employee_salary
{
private:
int basic,hra,ta,total_salary;
char name[100];
public:
employee_salary()
{
cout<<"======================================="<<endl;
cout<<"Employee Salary Information"<<endl;
cout<<"======================================="<<endl<<endl<<endl;
}
void get_info()
{
//char name[20];
cout<<"Enter the Employee Name:";
cin>>name;
cout<<endl;
cout<<"Enter the Basic Salary:";
cin>>basic;
cout<<endl;
cout<<"Enter the HRA:" ;
cin>>hra;
cout<<endl;
cout<<"Enter the TA:";
cin>>ta;
}
void display_info()
{
//total_salary=basic+hra+ta;
//cout<<name;
cout<<"***************************************"<<endl;
cout<<"Employee Salary Information"<<endl;
cout<<"***************************************"<<endl;
cout<<"Employee Name:"<<name<<endl;
cout<<"Basic Salary:"<<basic<<endl;
cout<<"House Rent Allowance:"<<hra<<endl;
cout<<"Travel Allowance:"<<ta<<endl;
total_salary=basic+hra+ta;
cout <<"Total Salary:"<<total_salary<<endl;
}
};
int main()
{
clrscr();
employee_salary e;
e.get_info();
e.display_info();
//e.employee_salary();
getch();
return (0);
}
14 Function Overloading
#include<iostream.h>
#include<conio.h>
class addition
{
public:
int num1,num2,num3;
int add(int num1,int num2)
{
return num1+num2;
}
};
void main()
{
clrscr();
addition obj;
cout<<"Addition of the Function 1 is:"<<obj.add(10,20)<<endl;
cout<<"Addition of the Function 2 is:"<<obj.add(40,50,60);
getch();
}
15 Inheritance
#include<iostream.h>
#include<conio.h>
class student_info
{
public:
char name[100], regno [20];
int m1,m2,m3,m4,total,avg;
void get_info()
{
cout<< "Enter the Student Name: ";
cin>>name;
cout<<endl;
cout<< "Enter the Student Register No: "; cin>>regno;
cout<<endl;
cout<< "Enter the Tamil Mark: ";
cin>>m1;
cout<<"Enter the English Mark: ";
cin>>m2;
cout<< "Enter the Maths Mark: ";
cin>>m3;
cout<< "Enter the History Mark: ";
cin>>m4;
}
};
cout<<"**************************************";
cout<<"\n"<<"Student Name is :"<<name;
cout<<"\n"<<"\n"<<"Student Register Number:"<<regno;
cout<<"\n"<<"\n"<<"********************************"<<"\n";
cout<< "Tamil Mark: "<<m1<<"\n";
cout<<"English Mark: "<<m2<<"\n";
cout<< "Math Mark: "<<m3<<"\n";
cout<<"History Mark: "<<m4<<"\n";
total=m1+m2+m3+m4;
cout<< "Total Mark is "<<total<<"\n";
avg=(m1+m2+m3+m4)/4;
cout<< " Average Mark is "<<avg;
}
};
void main()
{
student_mark obj1;
obj1.get_info();
obj1.display();
getch();
}