Category Archives: C++ programs

All C++ programs placed here!

CPP05 – Write a CPP program to create Student class with appropriate constructor and destructor

Write a CPP program to create Student class with appropriate constructor and destructor. Also show what happen when you try to attempt to access private data members from outside of the class. CODE:- #include<iostream.h> #include<string.h> #include<conio.h> class student { int roll; char name[25]; char addr[100]; int std; char div; long cont; public: void get_data(int,char*,char*,int,char,long); void… Read More »

CPP04 – (c) Write a CPP program to generate a Fibonacci series of 50 numbers .

(c) Write a CPP program to generate a Fibonacci series of 50 numbers . CODE:- #include<iostream.h> #include<conio.h> void main() { unsigned long T,i,X=0,Y=1; clrscr(); cout<<“\nFIBONACCI 50 SERIES ARE :- \n”; i=0; while(i<50) { T=X+Y; cout<<” “<<X; X=Y; Y=T; i++; } getch(); } SCREEN SHOTS:- OUTPUT:-  

CPP04 – (b) Write a CPP program to print whether a number is prime or not .

(b) Write a CPP program to print whether a number is prime or not . CODE:- #include<iostream.h> #include<conio.h> void main() { int NUM,I; clrscr(); cout<<“ENTER A NUMBER :”; cin>>NUM; for(I=2;I<NUM;I++) { if(NUM%I==0) break; } if(I==NUM) cout<<NUM<<” IS A PRIME NUMBER”<<endl; else cout<<NUM<<” IS NOT A PRIME NUMBER”<<endl; getch(); } SCREEN SHOTS:- OUTPUT:-  

CPP04 – (a) Write a CPP program to print the factorial of a given number.

(a) Write a CPP program to print the factorial of a given number. CODE:- #include<iostream.h> #include<conio.h> void main() { int i,num; long fact=1; clrscr(); cout<<“Enter Number : “; cin>>num; for(i=num;i>0;i–) { fact=fact*i; } cout<<“Factorial = “<<fact<<endl; getch(); } SCREEN SHOTS:- OUTPUT:-  

CPP03 – Write a CPP program to find the maximum marks, average-marks and minimum marks obtained by a study in five papers given

Write a CPP program to find the maximum marks, average-marks and minimum marks obtained by a study in five papers as given below: Paper 1            Paper 2            Paper 3            Paper 4            Paper 5 Marks              50                    70                    65                    80                    56 CODE:- #include<iostream.h> #include<conio.h> void main() { int… Read More »

CPP02 – Write a CPP program to explain the use of for loop, while loop, switch-case, break and continue statements.

CPP02 – Write a C++ program to explain the use of for loop, while loop, switch-case, break and continue statements. CODE:- #include<iostream.h> #include<conio.h> void main() { int i; clrscr(); cout<<“FOR LOOP”<<endl; for(i=1;i<6;i++) cout<<i<<endl; cout<<“WHILE LOOP”<<endl; while(i>1) cout<<–i<<endl; cout<<“DO WHILE LOOP”<<endl; do { cout<<i++<<endl; }while(i<6); getch(); } SCREEN SHOTS:- OUTPUT:-   CODE:- #include<iostream.h> #include<conio.h> void main()… Read More »

CPP01- Write a CPP program to find size and print the all basic data types of C++.

Write a CPP program to find size and print the all basic data types of C++. CODE:- #include<iostream.h> #include<conio.h> void main() { char c=’c’; int i=123; short s=12; long l=98775345; float f=456.789; double d=12345.6789; clrscr(); cout << “Value of char   : ” << c << endl; cout << “Value of int    : ” << i… Read More »