Skip to main content

Posts

Showing posts with the label C Plus Plus Programs

Make Your Own Header File in C & C++?

Make Your Own Header File ? Step1 : Type this Code int Multiplication( int a, int b) { return (a*b); } In this Code write only function definition as you write in General C Program Step 2 : Save Code Save Above Code with [.h ] Extension . Let name of our header file be myhead [Multhead.h ] Compile Code if required. Step 3 : Write Main Program #include<stdio.h> #include "Multhead.h" void main() { int number1=10,number2=10,number3; number3 = Multiplication(number1,number2); printf( "Addition of Two numbers : %d" ,number3); } Include Our New Header File . Instead of writing < Multhead.h> use this terminology “Multhead.h” All the Functions defined in the Multhead.h header file are now ready for use . Directly call function Multiplication(); [ Provide proper parameter and take care of return type ] Note While running your program precaution to be taken : Both files [ Multhead.h and sample.c ] should be in same folder. Technorati Tag...

Running Clock in C++ with Graphics

#include<conio.h> #include<graphics.h> #include<math.h> #include<dos.h> #define WBC 5 //^watchbackcolor #define X 200 #define Y 200 void dial( int x, int y); void sechand( int timeminute); void minhand( int t) { int x1,y1; setlinestyle(0,0,3); x1= X+ (80 * cos(t*0.1047)); y1= Y+ (80 * sin(t*0.1047)); setcolor(BLACK); line( X, Y, x1, y1); setcolor(WBC+1); line( X, Y, X+ 80 * cos((t-1)*0.1047),Y+ 80 * sin((t-1)*0.1047)); circle(X,Y,4); } void sechand( int t) { int x1,y1; setlinestyle(0,0,3); x1= X+(100 * cos(t*0.1047)); y1= Y+(100 * sin(t*0.1047)); setcolor(RED); line(X, Y, x1, y1); setcolor(WBC+1); line(X, Y, X+ 100 * cos((t-1)*0.1047),Y+ 100 * sin((t-1)*0.1047)); circle(X,Y,4); } void dial( int x, int y) { int const size=200; setfillstyle(1,WBC); fillellipse(x,y,size,size); setfillstyle(1,WBC+1); fillellipse(x,y,size-20,size-20); outtextxy(x,y-(size-40), "12" ); outtextxy(x,y+(size-40), "6" ); outtextxy(x+(s...

INHERITANCE IN C++

Inheritance: It is the capability of one class to inherit properties from another class. Base Class: It is the class whose properties are inherited by another class. It is also called Super Class. Derived Class: It is the class that inherit properties from base class(es).It is also called Sub Class. TYPES OF INHERITANCE Single Inheritance: It is the inheritance hierarchy wherein one derived class inherits from one base class. Multiple Inheritance: It is the inheritance hierarchy wherein one derived class inherits from multiple base class(es) Hierarchical Inheritance: It is the inheritance hierarchy wherein multiple subclasses inherits from one base class. Multilevel Inheritance: It is the inheritance hierarchy wherein subclass acts as a base class for other classes. Hybrid Inheritance: The inheritance hierarchy that reflects any legal combination of other four types of inheritance. Visibility Mode: It is the keyword that controls the visibility and avai...

CONSTRUCTOR AND DESTRUCTOR in C++

CONSTURCTOR It is a member function having same name as it’s class and which is used to initialize the objects of that class type with a legel initial value. Constructor is automatically called when object is created. Types of Constructor Default Constructor- : A constructor that accepts no parameters is known as default constructor. If no constructor is defined then the compiler supplies a default constructor. student :: student() {      rollno=0;      marks=0.0; } Parameterized Constructor - : A constructor that receives arguments/parameters, is called parameterized constructor. student :: student(int r) {      rollno=r; } Copy Constructor- : A constructor that initializes an object using values of another object passed to it as parameter, is called copy constructor. It creates the copy of the passed object. student :: student(student &t) {      rollno = t.rollno; } DESTRUCTOR A destructor is a...

C++ Casino Game Project

Description: This C++ program on CASINO GAME is a simple text base game.We have used procedure oriented method to design this game. This program is without grahics to keep program easy for beginners . Player can deposit his money to play. From this amount he can bet on number between 1 to 12. If he win he gets 10 times of money otherwise lost his money. In this project, We have used programming concept like do..while loop, user defined function, library function like randomize(), random() etc. #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<stdio.h> #include<time.h> void draw_line( int n, char ch); void rules(); void main() { int balanceamt,amt,no,dice; char playername[80],ch; clrscr(); draw_line(60,'='); cout<<" \n\n\n\n\t\tCASINO GAME\n\n\n\n "; draw_line(60,'='); cout<<" \n\n\nEnter Your Name : "; gets(playername); cout<<" \n\n\Enter Deposit amount to play game : ...

C++ TIC TAC TOE GAME PROJECT

  Description: This C++ program on TIC TAC TOE GAME is a simple text base game. This program is without grahics to focus on logic /algorithm used in game. Two players can play this game. #include <iostream.h> #include <conio.h> char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; int checkwin(); void board(); int main() { int player = 1,i,choice; char mark; clrscr(); do { board(); player=(player%2)?1:2; cout << " Player " << player << " , enter a number: "; cin >> choice; mark=(player == 1) ? 'X' : 'O'; if (choice == 1 && square[1] == '1') square[1] = mark; else if (choice == 2 && square[2] == '2') square[2] = mark; else if (choice == 3 && square[3] == '3') square[3] = mark; else if (choice == 4 && square[4] == ...

C++ HANGMAN GAME PROJECT

  Description: In the game of Hangman, the computer chooses a word at random from a given list of words. This word is the answer. The player then tries to guess the word, by guessing one letter at a time. Whenever the user guesses a letter that is in the answer, all occurrences of that letter are revealed to the user. The game ends when the user has guessed every letter in the word, before he reaches the allowed number of strikes.   #include <iostream.h> #include <stdlib.h> #include < string .h> #include <conio.h> const int MAXLENGTH=80; const int MAX_TRIES=5; const int MAXROW=7; int letterFill ( char , char [], char []); void initUnknown ( char [], char []); int main () { char unknown [MAXLENGTH]; char letter; int num_of_wrong_guesses=0; char word[MAXLENGTH]; char words[][MAXLENGTH] = { " india ", " pakistan ", " nepal ", " malaysia ", " philippines ", " australia ...

C++ Supermarket Billing Project

  Description: This C++ menu driven programs on SUPERMARKET BILLING SYSTEM has product class with data members like product no, product name, price, qty, tax, discount. Product details is stored in a binary file . A customer can purchase product and his invoice generated. Administrator can create, modify, view and delete product record. //*************************************************************** // HEADER FILE USED IN PROJECT //**************************************************************** #include<conio.h> #include<stdio.h> #include<process.h> #include<fstream.h> //*************************************************************** // CLASS USED IN PROJECT //**************************************************************** class product { int pno; char name[50]; float price,qty,tax,dis; public : void create_product() { cout<<" \nPlease Enter The Product No. of The Product "; cin>>pno; cout<<" \n\nPlease Enter The N...