Mar 30, 2007
Inkers
They says "One best thing to purchase from them is they give guarantee against defect for one year and a 30 days no question ask money back guarantee they give.
It is an cost effective alternative.
Inkers delivers free ground shipping and usually they deliver same day of orders
If you need any kind of guidance from them feel free to call them at their toll free number before 2PM Pacific at 800-848-7232 and they will be glad to guide you through. they always love to help your queries about ink cartrides.
So when you think about ink cartridges think about Inkers.
Mar 26, 2007
C++ program for Password input and check
C++ program to input and check a given password. if user input a correct password then program to add two number will be executed and a user input a wrong password. A message "Wrong password" would appeared on the screen and terminates the proram.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
for (int i=1;i<=5;i=i+1) // start, condition, increment
{
int a,b,c,x;
cout << "enter your password here";
cin >> x ;
if (x==1)
{\
cout <<"enter first number";
cin >> a;
cout <<"enter second number";
cin >> b;
c=a+b;
cout << c <<endl;
}
else
{
cout << "wrong password";
break;
}
}
getch();
}
Inheritance In C++
C++ program to demonstrate inheritance :
#include<iostream.h>
#include<conio.h>
class demo1 // base class
{
public :
void hello()
{
cout << "hello FROM DEMO1" <<endl;
}
};
class demo2 : public demo1 // derived class
{
public :
void hi()
{
cout << "hi FROM DEMO2" <<endl;
}
};
main()
{
clrscr();
demo2 d2;
d2.hello();
d2.hi();
getch();
}
Function Overloading in C++
Function overloading : two or more than two function in a program with same name but must be different in parameters.
#include<iostream.h>
#include<conio.h>
class demo
{
public :
void add()
{
int a,b,c;
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >>b;
c=a+b;
cout <<c <<endl;
}
void add(int a,int b)
{
int c;
c=a+b;
cout << c <<endl;
}
};
main()
{
clrscr();
int a,b;
cin >> a;
cin >> b;
demo d1;
d1.add();
d1.add(a,b);
getch();
}
// Here in above program there are two add fuctions. One is of without parameters
// and second one is with parameters.
File Handling in C++
File handling : to store data in a text/data file
Writing data to a text file
#include<iostream.h>
#include<conio.h>
#include<fstream.h> // file stream
main()
{
clrscr();
char name[10];
int salary;
ofstream f("unique"); // output file stream is a class name
for (int i=0; i<=4; i++)
{
cout <<"enter name :";
cin >> name;
cout << "enter salary :";
cin >> salary;
f<< name << "\t" << salary<<endl ;
}
getch();
}
// do the following things
/*
1 run the program
2 input some data
3 click file menu > dos shell
4 type the follwing command at dos prompt
type unique
it will display contents of the unique file.
*/
Exit() function in C++
exit function : is terminates entire program. Here it is used in for loop when the value of i is eqauls to 100 then exit(0) will be executed and the program will be terminated.
#include<iostream.h>
#include<conio.h>
#include<process.h> // requires to include for exit() function
main()
{
clrscr();
for (int i=1;i<=100; i++)
{
cout << i <<endl;
if (i==30)
exit(0); // it will termiate entire program
}
cout << "hello" <<endl; // this statement will never execute.
getch();
}
Mar 23, 2007
Default Argument Function in C++
default argument function : In this program function add have two parameters and one of them is default argument and has fix value 10. if this argument is passed when calling this function default value of the function will be omited. If this value is not passed then default value
is used as a function argument.
#include<iostream.h>
#include<conio.h>
class demo
{
public :
void add(int a,int b=10) // value of b is default.
{
int c=a+b;
cout << c <<endl;
}
};
main()
{
clrscr();
demo d1;
d1.add(20); // value of b will be 20 and default value if omited.
d1.add(); // value of b will be 10 it means default value is used.
getch();
}
Destructor in C++
destructor : is a member function of a class. it has same name as a class.
followed by a tilde sign ~ it does not have return type (neither int nor void) . it automatically
get executed when object is destroyed.
#include<iostream.h>
#include<conio.h>
class student // student is a class
{
public :
~student() // destructor
{
cout <<"Thanx for using this program" <<endl;
}
};
main()
{
clrscr();
student s1; // s1 is an object
getch();
}
Constructor in C++
// constructor : is a member function of a class. it must have same name
// as a class. it does not have any return type neither int nor void.
// it automatically get executed when object is created. it is used to
// initialize variables.
#include<iostream.h>
#include<conio.h>
class demo
{
public :
int a,b;
demo() // constructor
{
a=10;
b=20;
}
void add()
{
int c=a+b;
cout << c <<endl;
}
};
main()
{
clrscr();
demo d1;
// here object is created d1 of demo class and constructor get called automatically no need to
//call it explicitly.
d1.add();
getch();
}
Mar 20, 2007
IF condition in C++
IF condition : condition is formed after if keyword in a bracket.
if condition is satisfies then only statement within if block will be executed, if condition fails then statement within IF block will not be executed. if there is only one statement within if block then {} bracket can be omited if there are more than one statement within if block then statements of if block must be in {} brackets. If condition is formed using relational operators relational operators :
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a; // variale declaration
cout <<"enter any number";
cin >> a;
if (a>100)
{
cout << "Hello" <<endl;
}
if (a<100)
{
cout <<"hi" <<endl;
}
if (a==100)
{
cout <<"bye" <<endl;
}
if (a!=100)
{
cout <<"Unique" <<endl;
}
getch();
}
The above program demonstrates if condition using various relational operators
C++ class program (function with return value)
C++ class program (function with return value)
#include<iostream.h>
#include<conio.h>
class student // student is a class
{
public :
int add(int a,int b)
{
int c;
c=a+b;
return c;
}
};
main()
{
clrscr();
student s1;
int a,b;
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >> b;
int c=s1.add(a,b); // calling of a function
cout << c <<endl;
getch();
}
Function with parameter in a class
C++ (OOP) object oriented programming
function with parameter in a class.
#include<iostream.h>
#include<conio.h>
class student
{
public :
void add(int a,int b)
{
int c;
c=a+b;
cout << c <<endl;
}
};
main()
{
clrscr();
student s1;
int a,b,c;
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >> b;
s1.add(a,b); // calling of a function
getch();
}
Functions or Methods in a class
C++ (OOP) object oriented programming
functions in a class : functions in a class are known as methods or member functions
#include<iostream.h>
#include<conio.h>
class student // student is a class
{
public :
void add() // member function
{
int a,b,c;
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >> b;
c=a+b;
cout << c <<endl;
}
};
main()
{
clrscr();
student s1;
s1.add(); // calling of a function
getch();
}
C++ program to demonstrate class and object (OOP)
class : class is a template for an object. (master copy)
object : object is an instance of a class. (photo copy)
members of the class are by default private. private means members can not be accessible from anywhere in the prgraom excpet where it is defined.
This program to demonstrate C++ class/object
It will ask user to input roll no., name and marks of a student.
#include<iostream.h>
#include<conio.h>
class student
{
public :
int rn; // data members
char name[10];
float marks;
};
main()
{
clrscr();
student s1; // s1 is an object.
cout <<"enter any roll number";
cin >> s1.rn;
cout <<"enter name";
cin >> s1.name;
cout <<"enter any marks";
cin >> s1.marks;
getch();
}
C++ program to input a character
This program will accept a character from the keyboard and display it along with hello.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
char z;
cout << "enter any character";
cin >> z;
cout << "hello :";
cout << z <<endl;
getch();
}
C++ program to demonstrate single dimensional array
This program will accept qnantity of item and rate and calculate total amount and net amount.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int q[3],p[3],tot[3];
int net =0;
for(int i=0;i<=2;i++)
{
cout<<"ENTER QUANT. OF ITEMS :";
cin>> q[i];
cout<<"ENTER RATE IN PER KG :";
cin>> p[i];
tot[i]= q[i]*p[i];
cout<< tot[i] <<endl;
net = net + tot[i];
}
cout << "Grand total is=";
cout << net <<endl;
getch();
}
Mar 19, 2007
Type anywhere in the Microsoft word document
C++ Program to input/output a matrices
this program will take input for two 3x3 matrices m and n and then print them in matrix format and then it will add two of the matrix and store the result in third matrix (o).
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int m[3][3]; // matrix delcaration
int n[3][3];
int o[3][3];
for (int i=0;i<=2;i++) // first matrix input
{
for (int j=0;j<=2;j++)
{
cout <<"enter any number";
cin >> m[i][j];
}
}
for (i=0;i<=2;i++) // first matrix output
{
for (int j=0;j<=2;j++)
{
cout << m[i][j]<<" ";
}
cout <<endl;
} // second matrix input
for (i=0;i<=2;i++)
{
for (int j=0;j<=2;j++)
{
cout <<"enter any number";
cin >> n[i][j];
}
}
for (i=0;i<=2;i++) // second matrix output
{
for (int j=0;j<=2;j++)
{
cout << n[i][j]<<" ";
}
cout <<endl;
}
for (i=0;i<=2;i++) // adding both of the matrix
{
for (int j=0;j<=2;j++)
{
o[i][j] = m[i][j] + n[i][j];
}
cout <<endl;
}
for (i=0;i<=2;i++) // outputing the answer
{
for (int j=0;j<=2;j++)
{
cout << o[i][j] << " ";
}
cout <<endl;
}
getch();
}
C++ Program to design a admission form using Graphics
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
main()
{
int driver,mode;
driver=DETECT;
initgraph (&driver,&mode,"");
moveto(250,2);
settextstyle(1,HORIZ_DIR,4);
outtext("B A B A");
line(205,38,420,38);
moveto(200,40);
settextstyle(1,HORIZ_DIR,2);
outtext("COMPUTER EDUCATION");
moveto(330,80);
settextstyle(1,HORIZ_DIR,2) ;
outtext("ADDMISSION FORM ") ;
setcolor(15) ;
rectangle(80,80,510,110);
setfillstyle(1,2);
floodfill(388,100,15);
gotoxy(4,10);
cout<<"Date of add. :-";
gotoxy(4,11);
cout<<"Name :-";
gotoxy(4,12);
cout<<"Course :-";
gotoxy(4,13);
cout<<"Father's Name :-";
gotoxy(4,14);
cout<<"Date Of Birth :-";
gotoxy(4,15);
cout<<"Address :-";
gotoxy(4,16);
cout<<"City :-";
gotoxy(4,17);
cout<<"Tel.no. :- (O) (R) ";
gotoxy(4,18);
cout<<"Qualification No:-";
gotoxy(26,19 );
cout<<" 10 12 Graduate Other/ Subjects";
gotoxy(4,20);
cout<<"Computer Qual. :-";
gotoxy(4,21);
cout<<"Institution :-";
gotoxy(4,23);
cout<<"I DECLARE THAT I SHALL BE ABIDE BY THE LAWS OF THE INSTITUTION";
gotoxy(60,25);
cout<<"SIGNATURE";
line(180,155,500,155);
line(180,170,500,170);
line(180,185,500,185);
line(180,200,500,200);
line(180,215,500,215);
line(180,230,500,230);
line(180,245,500,245);
line(180,335,500,335 );
line(180,320 ,500,320 );
rectangle(215,255,280,270);
rectangle(320,255,385,270);
rectangle(530,6,630,110);
rectangle(2,0,638,478);
getch();
}
C++ Program to demonstrate single dimensional array
array : array is a group of elements of same data types. single dimensional array. this program will accepts 5 students marks and store them into an array m and then it will total them. array always start with 0. means first element always be 0.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int m[5];
int tot=0;
for (int i=0;i<=4;i++)
{
cout <<"enter any marks";
cin >> m[i];
tot = tot + m[i];
}
cout << tot <<endl;
cout << tot/5 <<endl;
getch();
}
C++ Program to input age to find out teen, young or old
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int age;
cout<<"enter the age in year(s)";
cin>>age;
if (age<1)
{
cout << "invalid age";
}
if(age>=1 && age<=3)
{
cout<<"baby"<<endl;
}
if(age>3 && age<=12)
{
cout<<"child"<<endl;
}
if(age>=13 && age<20)
{
cout<<"teenager"<<endl;
}
if(age>=20 && age<=45)
{
cout<<"young"<<endl;
}
if(age>45)
{
cout<<"old"<<endl;
}
getch();
}
C++ program to add, subtract, multiply and divide two given numbers
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a,b;
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >> b;
int c=a+b;
cout << c <<endl;
int d=a-b;
cout << d <<endl;
int e=a*b;
cout <<e <<endl;
int f=a/b;
cout << f <<endl;
getch();
}
C program to add two given numbers
Format Strings:
%d - integer
%f - float
%c - character
Then we come to the statement c=a+b. This statement will add the value of a and b and store into variable c. then printf() statement will print the value of c variable on the screen. Here + is an arithmetic operator. More arithmetic operators can be used such as - (subtract), * (Multiply), / (Divide), % (Mod or Remainder). getch() statement is a get character statement. It pause the output until user presses a key from the keyboard.
#include<stdio.h> // standard input output header file
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("enter any number");
scanf("%d",&a); // or cin >> a
printf("enter any number");
scanf("%d",&b);
c=a+b;
printf("%d",c);
getch();
}
Other C & C++ Programs:
C program to generate even numbers
C program to generate odd numbers
C program to generate table of any given number
C program to generate pyramid of stars
C program to generate upside down pyramid of stars
C program to generate beep sound
C program to generate melodious sound
C program to generate concentric circles using graphics
C program to add, multiply, subtract, divide two numbers
Mar 13, 2007
C++ program to draw concentric circles
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
main()
{
clrscr();
int driver,mode;
driver = DETECT;
initgraph(&driver,&mode,"C:\TC\BGI");
for(int i=1;i<=50;i=i+5)
{
circle(100,100,i);
delay(100);
}
getch();
closegraph();
}
Mar 12, 2007
C++ program to generate 10 random numbers between 1 to 100
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
main()
{
clrscr();
randomize();
for(int i=1;i<=10;i++)
{
cout << random(100)<<endl;
}
getch();
}
Mar 7, 2007
What is an action in Photoshop?
Most of the commands can be included in actions but some are not.
Start Photoshop and then click “Window > Show Actions”. It will display action palette as shown below.
Mar 5, 2007
C++ Program to count vowels in given string
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
main()
{
int i;
clrscr();
char st[40];
cout<<"Enter Any String Maximum 40 Characters";
gets(st);
i=0;
for (int k=0;st[k]!='\0';k++)
{
if(st[k]=='a' st[k]=='A' st[k]=='e'
st[k]=='E' st[k]=='i' st[k]=='I'
st[k]=='o' st[k]=='O'st[k]=='u'
st[k]=='U')
i++;
}
cout<<endl<<"The of Vowels in this string is = "<<i;
getch();
}
C++ Program to find out largest of three given numbers
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
cout<<"Enter Value of A : ";
cin>>a;
cout<<"Enter Value of B : ";
cin>>b;
cout<<"Enter Value of C : ";
cin>>c;
if (a>b && a>c)
cout<<endl<<"The largest no. is A";
if (b>a && b>c)
cout<<endl<<"The largest no. is B";
if (c>a && c>b)
cout<<endl<<"The largest no. is C";
getch();
}
C++ Program to count uppercase, lower case and numbers in given string
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
main()
{
clrscr();
char st[40];
int u,l,d,o,i;
u=i=d=o=l=0;
cout<<"Enter a string maximum 40 characters";
gets(st);
for (i=0;st[i]!='\0';i++)
{
if(st[i]>=65 && st[i]<=90)
u++;
if(st[i]>=97 && st[i]<=122)
l++;
if(st[i]>=48 && st[i]<=57)
d++;
}
cout<<endl<<"The Total upper case characters is : "<<u;
cout<<endl<<"The Total lower case characters is : "<<l;
cout<<endl<<"The Total digit is : "<<d;
getch();
}
Mar 2, 2007
C++ program to generate a table from any given number upto any given number
// or C++ program to generate a table between a given range.
// in this program there will be two input num1 and num2 and table will be
// generated between given num1 and num2.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int num1,num2;
cout <<"enter first number";
cin >> num1;
cout <<"enter second number";
cin >> num2;
for (int i=num1;i<=num2;i++)
{
for(int k=1;k<=10;k++)
{
cout << i*k<<endl;
}
getch();
}
getch();
}
Write above program in c++ editor and run. Give first input 2 and second input 5
then table will be generated from 2 to 5.