Sie sind auf Seite 1von 20

1.

Find the given number is Positive or Negative

Aim : Write a program to find the given number is positive or negative

#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;

cout << "Enter the year in yyyy format : ";


cin >> year;
if (year % 4 == 0)
cout << year << " is a leap year";
else
cout << year << " is not a leap 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()

char s1[30], s2[30], temp [30];


int val;
cout<<"\n Enter the String 1 ";
cin>>s1;
cout<<"\n Enter the String 2 ";
cin>>s2;
val=strcmp(s1,s2);

if (val==0)

cout<<"\n Strings are same: ";

else

cout<<"\n Strings are not same: ";

strcpy(temp,s1);
strcat(temp,s2);
cout<<"String Concatenate is"<<temp;
getch();

return 0;

4 Displaying N numbers using for Loop


Aim : Write a Program to display N numbers using C++

#include<iostream.h>

#include<conio.h>

void main()

int i,n;

clrscr();

cout<<"Enter the Number to Display";

cin>>n;

for(i=0;i<=n;i++)

cout<<i<<endl”;

getch();

5 Sum of N numbers using for Loop


Aim : Write a Program to sum the N numbers using C++

#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,sum;
sum=0;
clrscr();

cout<<"Enter the Number to Display:";


cin>>n;
for(i=0;i<=n;i++)
{
Sum=sum+i;
}

cout<<"Sum of the Input Number: "<<n<<"is :"<<sum;


getch();

}
6 Display Tables

Aim : Write a Program to display the Tables using for Loops


#include <iostream.h>
#include <conio.h>

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

Aim : Write a Program to 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

Aim : Write a Program to Sum the 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;

cout << "Enter the Second Number: ";


cin >> n2;
cout<<endl;

cout << "Enter the Third Number: ";


cin >>n3;
cout<<endl;

if(n1>= n2 && n1>= n3)


{
cout << "Largest number: "<< n1;
}
if(n2>= n1 && n2>= n3)
{
cout << "Largest number: "<< n2;
}
if(n3 >= n1 && n3 >= n2)
{
cout << "Largest number: " << n3;
}
getch();
}
10 Display week day using Switch Case Statement
Aim : Write a Program to Display the week day using Switch Case in C++
#include<iostream.h>
#include<conio.h>
void main()
{
int dow=2;
cout<<"Enter number of week's day (1-7): ";
cin>>dow;
switch(dow)
{
case 1 : cout<<"\nSunday";
break;
case 2 : cout<<"\nMonday";
break;
case 3 : cout<<"\nTuesday";
break;
case 4 : cout<<"\nWednesday";
break;
case 5 : cout<<"\nThursday";
break;
case 6 : cout<<"\nFriday";
break;
case 7 : cout<<"\nSaturday";
break;
default : cout<<"\nWrong number of day";
break;
}
getch();

}
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<<"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 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<< "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()

{
friend_function f;
display();
getch();
}
13 Constructor

Aim : Write a C++ program to display the Employee Salary Information by


Using 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

Aim : Write a Function Overloading program for addtion operation

#include<iostream.h>
#include<conio.h>
class addition
{
public:

int num1,num2,num3;
int add(int num1,int num2)
{
return num1+num2;
}

int add(int num1,int num2, int num3)


{
return num1+num2+num3;

};

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

Aim : Write a Inheritance program to display the Student’s Makr Inforamtion

#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;
}
};

class student_mark : public student_info


{
public:
void display()
{

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();
}

Das könnte Ihnen auch gefallen