0% found this document useful (0 votes)
725 views236 pages

Programs

The document provides a list of 100 C++ programs with descriptions. The programs cover a range of topics including data structures, algorithms, file handling, string manipulation, mathematical functions, and more. The programs are intended to help learn and practice various C++ concepts. Instructions are provided at the top for opening and compiling the program files.

Uploaded by

m_shahnawazjaved
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
725 views236 pages

Programs

The document provides a list of 100 C++ programs with descriptions. The programs cover a range of topics including data structures, algorithms, file handling, string manipulation, mathematical functions, and more. The programs are intended to help learn and practice various C++ concepts. Instructions are provided at the top for opening and compiling the program files.

Uploaded by

m_shahnawazjaved
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LIST OF PROGRAMS ON C++

by

[Link]
Your complete computer science portal

For any queries, write at: attention@[Link]

Instructions
DOUBLE CLICK TO OPEN THE FILE IN NOTE PAD TO VIEW AND COMPILE IT THROUGH THE TC COMPILER DIRECTLY

BY SPECIFYING THE F3 COMMAND TO OPEN AND SELECT D DRIVE WHERE THE CD IS INSERTED

OR
COPY ALL THE FILES IN THE TC DIRECTORY AND COMPILE & RUN ACCORDINGLY
FILE NAME/ DESCRIPTION OF THE PROGRAM [Link] Program to find all the combinations that you can make with one word example: abc > 9 combinations [Link] Program adds two numbers in binary using class and object. [Link] Program to perform updation of a data file for manipulating an address book [Link] Program using structure to define a Bank A/c System [Link] Program to conduct binary search for any alphabet [a-z] out of an array. [Link] Program to print prime factorization [Link] This C++ program displays the month of any year and also has controls to view the previous & the Next months. [Link] Program to display all prime fibonacci series within the range of 1 to 10000. [Link] Program to print the corresponding ASCII character [Link] Program to get the day the month starts on, and the number of days in the month to output a calendar. [Link] Program to define a class point and implement operations [Link] Program to input any string upto 500 characters and convert the same into binary [Link] Program to depict the usage of Binary Search Technique. It is assumed that the list of numbers in an array is stored in ascending order. [Link] Declaration of a Class and manipulation of member function. Display of the result of students with computed grade of marks. [Link] Program to display Fibonaccis Heap [Link] Program to Calculate Polynoms

[Link] Program for : Matrices : To implement cell value of a defined matrix Input: Row & Col. and Output : Cell element of the points Row, Col. [Link] Program to demonstrate reversing of an input text using a function with string arguments. [Link] Program to create a data file and read it as well. [Link] Program implementing File Operations Assuming the class student, [Link] Program to create a data file to store any ten rollnumbers and total marks and arrange the list in ascending order of marks. Read the file and print the new list obtained. [Link] Program to modify a record after creation in a data file. [Link] Program to add and reduce two given fractions [Link] Program to implement leap year checking using functions [Link] Program to implement sum of two input times. [Link] Program to add any two given angles. [Link] Program to compute the lcm and hcf using class. [Link] Project Programme for Hospital Database Queue array. [Link] Program that reads numbers (until -1 entered or more then 1000) into in array and sorts them in descending order. [Link] Program to extract maximum prime digit from a number [Link] Program to extract the position of any alphabet in the alphabetical series [Link] Array sorting: Using Bubble Sorting Technique. [Link] Program to compute the sum of all numbers divisible by 10 out of a given list. [Link] Program implements de-queues using circular arrays. De-queues are queues in which elements can be inserted/ deleted from either end. [Link] Adding elements of two given arrays into the third array. [Link] Program to print the sum of the following series: 1 + (1+2)+(1+2+3)+......N where N is the input.

[Link] Program to convert binary to decimal using a function. [Link] Program to convert any entered decimal number into binary. [Link] Program to create two arrays of 3x4 and compute their sum in a new array. Display the new array so obtained. [Link] Program to assign names of any four subjects and check if it is present using double dimensional arrays. [Link] Program to count the number of words within an entered string and also print the string in reverse. [Link] Program to count the number of words within an entered string and also print the string in reverse. [Link] Program which calculates the day of the week for any given date & month of the year 2002. [Link] Program to Identify the day on a particular date [Link] Program to create a doubly linked list, to add an item(in front,in middle or in end), to delete an element(in front,in middle or in end) and to display to elements in the nodes. [Link] Program to compute the determinant of the matrix. [Link] Program implementing File Streaming : Storing array of numbers in a data file [Link] Program to implement Calculator functions for : +, -, *, /, ^ [Link] Program to compute surface area of cone, cylinder, vol. of cone etc. [Link] Program for computation of: 1). Natural Log (Ln) 2). Log with Base 10(Log10) 3).Log of your desired Base (LogA^x) [Link] Program to implement calculation on any entered two numbers. [Link] Program will ask the user for a starting number and an ending number and compute the sum of the numbers in between. [Link] Program implementing all four types of sorting of a string. [Link]

Program implementing Bubble Sort for an entered range of numbers. Using passing of array for sorting through functions. [Link] Program to conduct: Array sorting: Using Insertion Sorting Technique. Program to input any five numbers and print them in descending order. [Link] Program to display Fibonacci numbers which are prime. [Link] Adding two angles. [Link] Searching element in an array using binary search [Link] Program to implement Function Overloading [Link] Program to implement bubble sort for a multi-dimensional array[10][20] The array is stored through random generation of numbers between the defined range 1 to 500 [Link] Program for Data File Manipulation of data entry/storage of employees Writing Structures in a data file. [Link] Program to accept a number x. Count number of digits in x and store it in n, form y that has the number of digits n at tens place and the most significant digit of x at ones place. Display y. sample input: x= 16833, y = 51, since [Link] digits of x is 5 and 1 is the msd of x. [Link] Program to implement Linked List. [Link] Program to combine two arrays and sort them in order in one. [Link] Lottery Game [Link] Program to depict the process of linear search [Link] Program to return the inverse of any entered number. [Link] Program to input a number and check if it is a Magic Number [Link] This program creates a magic square box of order n x n. The speciality of a magic square box is that the sum of elements of any row or any column is always equal. [Link] Program to insert comma at appropriate position in an entered (max-15) digit number as per the mathematical theory. [Link] Program to display Consonants and Vowels output from an entered string [Link] Program to perform: Matricies-add,subtract & more.

[Link] Program for reading, writing and multiplication of the matrices. [Link] Program to perform MergeSort [Link] Program in C++ to create a 3 by 3 array and extract the maximum and the maximum alongwith the original matrix. [Link] Program to convert any numeric entry into Words. [Link] Program to perform Magic Courtesy : ENRICO X THE MAGICIAN : Enrico Lorenzo Source: Internet [Link] Program to design a Five Function Calculator using Switch/Case [Link] Conversion program using Fucntions. [Link] Program to display all prime fibonacci series within the range of 1 to 10000. [Link] Program to display a Triangle of numbers called the Pascals Triangle, when provided with the number of rows. [Link] Program to input any string and print the number of spaces stored within the string at prime positions. [Link] Program for Pig Latin Converter [Link] The program calculates the value of a polynomial [Link] Program to assign string in a double dimensional array and display the contents. [Link] Program to print the product of two matrices [Link] Program for converting an int variable to floating point [Link] Program to play a puzzle [Link] Program to print out a checkered board of size n. [Link] Program to Print out a diamond of any size less than 12 [Link] Program to implement a Recursive Function [Link] Program to delete the first common word in two strings and display the strings without the first common words. [Link]

Program to input any string and print the number of words. [Link] Rotates a word This program prints all the rotation of a word. Say if the input word is space, then it prints space paces acesp cespa espac [Link] This function allows the user to enter a number and than rounds it off, correct to the nearest integer. [Link] Using Selection Sorting Technique. Program to input any ten numbers and print them in ascending order. [Link] Program to input any string and print the number of 'the'. [Link] Program to input a string and a character. Print the frequency of the character within the string. [Link] Program to sort the given strings in Ascending order. [Link] Program to output:- Number of upper case alphabets (A, B, C, ....) Number of lower case alphabets (a, b, c, ......) Number of Special Characters (., + - / etc.)

[ For Advanced Programs visit [Link]]

// Program to find all the combinations that you can make with // one word example: "abc" -> 9 combinations -> abc - acb - bac // - bca - etc... #include <iostream.h> #include <string.h> // Program to display the all available // unique combinations of a given string of any length. #include <iomanip.h> #include<conio.h> typedef char string[80]; long fac(int getal) // { long faculteit = 1; for (; getal>1; getal--) faculteit*=getal; return faculteit; } // long fac(int getal) void swapchars(string tekst, int char1, int char2) // { char hulp; hulp=tekst[char2]; tekst[char2]=tekst[char1]; tekst[char1]=hulp; } // int findcombo(string tekst, int positie) { int teller = 1; int nulpos = positie; long faculteit; string oldtekst; faculteit = fac(strlen(tekst)-positie); while (teller<=faculteit) { if (positie<strlen(tekst)-1) positie++; if (faculteit>2) { strcpy(oldtekst,tekst); teller+=findcombo(tekst,nulpos+1); strcpy(tekst,oldtekst); swapchars(tekst,nulpos,positie); } else { teller++; swapchars(tekst,nulpos,positie);

[Link] AM [Link]

cout << tekst << "\n"; } } return faculteit; } // int main(void) { clrscr(); string tekst; cout << "The entered words is : "; cin >> tekst; cout << endl<<"Word: " << tekst << "\n"; cout << "Obtained combination: " << fac(strlen(tekst)) << " "; findcombo(tekst,0); getch(); return 0; }

[Link] AM [Link]

// Program adds two numbers in binary using class and object. #include<iostream.h> #include<conio.h> //using namespace std; class adder{ public: int number1[8]; int number2[8]; int carry[8]; int sum[8]; int number_bits; char choice;

void input(){ cout<<"Input the number of bits you want to enter\n"; cout<<"For the first number \n"; cin>>number_bits; if(number_bits<0||number_bits>8){ cout<<"Error, the number of bits cannot be allowed to be \n"; cout<<"greater than 8 or less than 0\n"; cout<<"Please,Input the number correct entry\n"; cout<<"For the first number \n"; cin>>number_bits; } if(number_bits<8){ for(int k=1;k<=(8-number_bits);k++){ number1[k]=0; } } cout<<"Enter the bits as 1 or 0 from the most significant bit\n"; for(int i=(9-number_bits);i<=8;i++){ cout<<"Enter bit "<<i-(8-number_bits)<<" : "; cin>>number1[i]; } cout<<"Input the number of bits you want to enter\n"; cout<<"For the second number \n"; cin>>number_bits; if(number_bits<0||number_bits>8){ cout<<"Error, the number of bits cannot be allowed to be \n"; cout<<"greater than 8 or less than 0\n"; cout<<"Please,Input the number correct entryr\n"; cout<<"For the second number \n";

[Link] AM [Link]

cin>>number_bits; } if(number_bits<8){ for(int k=1;k<=(8-number_bits);k++){ number2[k]=0; } } cout<<"Enter the bits as 1 or 0 from the most significant bit\n"; for(i=(9-number_bits);i<=8;i++){ cout<<"Enter bit "<<i-(8-number_bits)<<" : "; cin>>number2[i]; } cout<<"THE FIRST NUMBER YOU HAVE ENTERED \n"; cout<<"NUMBER ONE: "; for(int l=1;l<=8;l++){ cout<<number1[l]; cout<<" "; } cout<<endl; cout<<"THE SECOND NUMBER YOU HAVE ENTERED \n"; cout<<"NUMBER TWO: "; for(l=1;l<=8;l++){ cout<<number2[l]; cout<<" "; } cout<<endl; } void check(int array[],int size){ for(int b=1;b<=size;b++){ array[b]; } for(b=1;b<=size;b++){ if((array[b]!=0)&&(array[b]!=1)){ cout<<"One of the entry is not 1 0r 0\n"; cout<<"please update it, go back to A on the menu\n"; break; } else{ cout<<"The entries are in binary, ok\n"; break; } } } char uppercase(char ch){ switch(ch){
[Link] AM [Link]

case'a':return'A';break; case'b':return 'B';break; case'c':return 'C';break; case'd':return 'D';break; case'e':return 'E';break; case'f':return 'F';break; case'g':return 'G';break; case'h':return 'H';break; case'i':return 'I';break; case'j':return 'J';break; case'k':return 'K';break; case'l':return 'L';break; case'm':return 'M';break; case'n':return 'N';break; case'o':return 'O';break; case'p':return 'P';break; case'q':return 'Q';break; case'r':return 'R';break; case's':return 'S';break; case't':return 'T';break; case'u':return 'U';break; case'v':return 'V';break; case'w':return 'W';break; case'x':return 'X';break; case'y':return 'Y';break; default:return ch;break; } } void adding(int x[],int j,int y[],int k){ carry[8]=0; for(int g=8;g>=1;g--){ if((x[g]+y[g]+carry[g])==0){ sum[g]=0; carry[g-1]=0; } if((x[g]+y[g]+carry[g])==1){ sum[g]=1; carry[g-1]=0; } if((x[g]+y[g]+carry[g])==2){ sum[g]=0; carry[g-1]=1; } if((x[g]+y[g]+carry[g])==3){ sum[g]=1; carry[g-1]=1; } } cout<<"THE SUM OF NUMBERS ENTERED IS \n";
[Link] AM [Link]

for(int r=1;r<=8;r++){ cout<<sum[r]; cout<<" "; } if(carry[1]==1){ cout<<"over flow of "; cout<<carry[1]; cout<<endl; } } }; int main(){ clrscr(); adder sum; [Link]='Y'; while([Link]=='Y'){ cout<<"\n"; cout<<" Choose from the following \n"; cout<<" A: Input of two numbers in binary \n "; cout<<"B: Check the entry of numbers \n"; cout<<" C: Adding the two numbers \n"; cout<<" "; cin>>[Link]; [Link]=[Link]([Link]); switch([Link]) { case 'A': [Link](); break; case 'B': cout<<"Checking the first number\n"; [Link](sum.number1,8); cout<<"Checking the second number\n"; [Link](sum.number2,8); break; case 'C': [Link](sum.number1,8,sum.number2,8); break; default: cout<<"Sorry, your selection is not right \a\n";break; } cout<<"\n"; cout<<"Do you want to experiment some more [Y/N] ?\n"; cin>>[Link]; cout<<"\n";
[Link] AM [Link]

[Link]=[Link]([Link]); if([Link]=='N'){ cout<<"END.......\n"; cout<<endl; } clrscr(); } return 0; }

[Link] AM [Link]

//Program to perform updation of a data file // for mainipulating an address book #include<stdio.h> #include<stdlib.h> #include<fstream.h> #include<string.h> #include<conio.h> #define ENTER 13 #define BACK 8 struct student { char name[30]; char proff[40]; char address[20]; char country[20]; char tel[20]; char fax[20]; char mobile[20]; char email[50]; }; class data { private: student std; int j,count; char sname[50],pass[10],c; public: struct student getData(); void showData(struct student); void saveData(); int readData(); void delet(); void modify(); void searchData(); void emergency(); void password(); int checkpass(); void modpass(); char* takepass(); int checkvalidity(char []); }; student data::getData() { cout<<"Name : "; gets([Link]); cout<<"Proffession : "; gets([Link]); cout<<"Address : ";

[Link] AM [Link]

gets([Link]); cout<<"Country : "; gets([Link]); cout<<"Telephone : "; gets([Link]); cout<<"Fax : "; gets([Link]); cout<<"Mobile : "; gets([Link]); cout<<"[Link] : "; gets([Link]); } void data:: showData(student str) { clrscr(); cout<<"\nName : "<<[Link]; cout<<"\nProffession : "<<[Link]; cout<<"\nAddress : "<<[Link]; cout<<"\nCountry : "<<[Link]; cout<<"\nTelephone : "<<[Link]; cout<<"\nFax : "<<[Link]; cout<<"\nMobile : "<<[Link]; cout<<"\[Link] : "<<[Link]; getch(); } void data::modify() { char dname[30]; int l; int coutn=0,choice; int k=0; l=checkpass(); if(l==1) { cout<<"\nPlease mention the name to be modified : "; cin>>dname; fstream infile; [Link]("[Link]",ios::in|ios::out); [Link](0); if(infile) { while([Link]((char *)&std,sizeof(student))) { coutn++; char ans='y'; if(stricmp([Link],dname)==0) { k=1; while(ans=='y'||ans=='Y') { clrscr(); cout<<"What do you want to modify\[Link]\[Link]\[Link] "; cout<<"\[Link]\[Link] Number\[Link] Number\[Link]"; cout<<"\n8.E-mail\t";
[Link] AM [Link]

cin>>choice; switch(choice) { case 1: cout<<"Name : "; cin>>[Link]; break; case 2: cout<<"Proffession : "; cin>>[Link]; break; case 3: cout<<"Address : "; cin>>[Link]; break; case 4: cout<<"Country : "; cin>>[Link]; break; case 5: cout<<"Telephone : "; cin>>[Link]; break; case 6: cout<<"Fax : "; cin>>[Link]; break; case 7: cout<<"Mobile : "; cin>>[Link]; break; case 8: cout<<"E-mail : "; cin>>[Link]; break; default: cout<<"Wrong choice "; break; } cout<<"\nAnything More to modify "; cin>>ans; } [Link]((coutn-1)*sizeof(student)); [Link]((char *)&std,sizeof(student)); } } if(k!=1) cout<<"The name doesn't exist "; else cout<<"The name has been successfully modified "; } } else cout<<"access denied ";
[Link] AM [Link]

getch(); } void data::delet() { char dname[30]; int coutn=0; int k=0; if(checkpass()==1) { cout<<"\n\nPlease mention the name to be deleted : "; gets(dname); fstream infile; [Link]("[Link]",ios::in|ios::out); [Link](0); if(infile) { while([Link]((char *)&std,sizeof(student))) { coutn++; if(stricmp([Link],dname)==0) { k=1; strcpy([Link]," "); strcpy([Link]," "); strcpy([Link]," "); strcpy([Link]," "); strcpy([Link]," "); strcpy([Link]," "); strcpy([Link]," "); strcpy([Link]," "); [Link]((coutn-1)*sizeof(student)); [Link]((char *)&std,sizeof(student)); break; } } if(k!=1) cout<<"The name doesn't exist "; else cout<<"The name has been successfully deleted "; } } else cout<<"\n\nAccess Denied "; getch(); } void data:: saveData() { ofstream outfile; [Link]("[Link]",ios::app); [Link]( (char *)&std,sizeof(student)); } int data::readData() {
[Link] AM [Link]

count=0; ifstream infile; [Link]("[Link]",ios::app); if(infile) { while([Link]((char *)&std,sizeof(student))) { if(strcmp([Link]," ")!=0) showData(std); count++; } } else cout<<"no file"; return(count); } void data::emergency() { char emer[30]; int j=0; cout<<"Please type the name to be searched: "; gets(emer); ifstream infile; [Link]("[Link]",ios::nocreate); while([Link]((char *)&std,sizeof(student))) { if(stricmp(emer,[Link])==0) { j=1; showData(std); } } if(j==0) cout<<"Sorry the name doesn't exist"; getch(); } void data::searchData() { j=0; cout<<"Please type the name to be searched: "; gets(sname); ifstream infile; [Link]("[Link]",ios::nocreate); while([Link]((char *)&std,sizeof(student))) { if(stricmp(sname,[Link])==0) { j=1; showData(std); } } if(j==0) cout<<"Sorry the name doesn't exist"; }
[Link] AM [Link]

void data::password() { char fre[20]; int pd; clrscr(); cout<<endl<<endl<<"Password "; strcpy(fre,takepass()); pd=checkvalidity(fre); clrscr(); if(pd==1) cout<<"This password already exist Please try for new password "; else { strcpy(pass,fre); ofstream passfile; [Link]("[Link]",ios::app); [Link](pass,sizeof(pass)); cout<<"Passwords are sensitive do not lend it "; } } int data::checkvalidity(char fre[]) { int idm=0; ifstream passfile; [Link]("[Link]",ios::app); while([Link](pass,sizeof(pass))) { if(stricmp(fre,pass)==0) { idm=1; break; } } return idm; } void data::modpass() { char d[20],npass[20]; clrscr(); int me=0,in=0; cout<<endl<<endl<<"Old Password "; strcpy(d,takepass()); fstream infile; [Link]("[Link]",ios::out|ios::in); { while([Link](pass,sizeof(pass))) { me++; if(strcmp(d,pass)==0) { in=1;
[Link] AM [Link]

cout<<"\nOK the password exist "; getch(); clrscr(); cout<<endl<<endl<<"New password "; strcpy(pass,takepass()); [Link]((me-1)*sizeof(pass)); [Link](pass,sizeof(pass)); } } } if(in==0) cout<<"\nThe password doesn't exist "; else cout<<"\nThe password has been successfully modified "; getch(); } int data::checkpass() { char da[20]; int z=0,to=0,u=0; clrscr(); ifstream passfile; [Link]("[Link]",ios::app); while(to<1&&z!=1) { to++; cout<<endl<<endl<<"Your password "; strcpy(da,takepass()); [Link](0); while([Link](pass,sizeof(pass))) { clrscr(); if(strcmp(da,pass)==0) { z=1; break; } } } return z; } char* data::takepass() { char ma[20],pa[20]; int q=0,row=30,col=3; int i=0; gotoxy(30,3); while((c=getch())!=ENTER) { if(c==BACK) {
[Link] AM [Link]

gotoxy((row-1),col); cout<<" "; row--; i--; } else { ma[i]=c; i++; gotoxy(row,col); cout<<"*"; row++; } } ma[i]='\0'; strcpy(pa,ma); clrscr(); return pa; } void main() { clrscr();//Clearing the screen. int ch,i,k,a; char choice,sm[20]; data s; srand(time(NULL)); a=1+(rand()%100); textcolor(WHITE); while(1) { clrscr(); cout<<"Your Choices"; cout<<"\[Link] datas\[Link] From File\[Link] data\[Link]\[Link]\[Link] Emergency Contacts\t"; cout<<"\[Link] New Password\[Link] Password\[Link]\t"; cin>>ch; switch(ch) { case 1: cout<<"How many datas do u want to feed " ; cin>>i; for(k=0;k<i;k++) { [Link]( ); [Link](); } break; case 2: [Link](); getch(); break; case 3: [Link](); getch();
[Link] AM [Link]

break; case 4: [Link](); break; case 5: [Link](); break; case 9: exit(0); case 7: cout<<"Please mention Your institution "; cin>>sm; if((strcmpi(sm,"spsl")==0)&&(a%4==0)) [Link](); else if((strcmpi(sm,"spsl")==0)&&(a%4!=0)) { clrscr(); textcolor(LIGHTRED+BLINK); gotoxy(25,10); cout<<"Sorry the system is busy"; } else { clrscr(); gotoxy(25,10); textcolor(LIGHTRED+BLINK); cout<<"\nYOU ARE NOT THE LEGAL PERSON "; } getch(); textcolor(WHITE); break; case 8: [Link](); break; case 6: [Link](); break; default: cout<<"\nWrong Choice "; getch(); } } getch(); }

[Link] AM [Link]

// Program using structure to define a Bank A/c System #include "iostream.h" #include "conio.h" #include "stdio.h" struct account { int no[10]; char name[20]; long int d,b,a; long double t; }; void main() { clrscr(); window(27,2,53,4); textbackground(3); clrscr(); textcolor(0); cprintf(" \n BANK ACCOUNT SYSTEM"); /*menu*/ window(20,5,60,25); textbackground(13); clrscr(); gotoxy(2,3); textcolor(10); cprintf("G"); gotoxy(3,3); textcolor(14); cprintf("ive The Account No."); /*name of the account holder*/ textcolor(10); gotoxy(2,5); cprintf("E"); textcolor(14); gotoxy(3,5); cprintf("nter The Name "); /*balance*/ textcolor(10); gotoxy(2,7); cprintf("A"); textcolor(14); gotoxy(3,7); cprintf("mount"); /*amount*/ account i; /*input*/ gotoxy(22,3); cin>>[Link][10]; gotoxy(22,5); cin>>[Link]; gotoxy(22,7); cin>>i.a;

[Link] AM [Link]

gotoxy(3,14);textcolor(11); cout<<"Name: "<<[Link]; /*runtime calculations*/ /*******************************for deposit*******************************/ i.d=i.a+5; gotoxy(3,16); cout <<"The Deposite Is: "<<i.d; /****************************Tax Deduction ***********************************/ i.t=700.8/i.d*100; gotoxy(3,18); cout <<"The deduced Tax is :"<<i.t; gotoxy(15,35); cout <<"%"; /***************************For Balance**********************************/ i.b=i.d-i.t; /********** object of the struct account********************/ if (i.b>0 && i.a<=i.b) { gotoxy(3,20); cout <<"WITHDRAW THE BALANCE :"<<i.b; } else { gotoxy(3,20);textcolor(11); cprintf("Can't Withdraw Your Balance!!!");} getch(); }

[Link] AM [Link]

// Program to conduct binary search // for any alphabet [a-z] out of an array. #include <ctype.h> #include <conio.h> #include <iostream.h> #define max 26 char array[max] = "\0"; void initialise() { for(int i=0; i<max; i++) { array[i] = (char)(65+i); } } int binsearch(int low, int high, int &num) { int mid = (high+low)/2; if( array[mid] == num ) { return mid; } else if( low >= high ) { return -1; } else if( num > array[mid] ) { return binsearch(mid+1, high, num); } else if( num < array[mid] ) { return binsearch(low, mid-1, num); } else return -2; } void main() { char alpha; int number; int result; clrscr(); initialise(); cout << "Enter the alphabet to search [lower case]: "; cin >> alpha;

[Link] AM [Link]

number = (int)toupper(alpha); result = binsearch(0, max, number); if( result >= 0 ) { cout << "Found at index # : " << result+1; } else if( result == -1 ) { cout << "Not Found"; } else cout << "Unspecified Error"; getch(); }

[Link] AM [Link]

// Program to print prime factorization #include<conio.h> #include <stdio.h> #include <stdlib.h> #include <fstream.h> main() { clrscr(); char line[512]; /* input string */ short ii; /* number to be factored */ short j; /* divisors */ short p; /* powers of j in ii */ cout<<"Please enter the number to be factored: "; [Link](line, 512); ii = atoi(line); cout<<"The prime divisors of "<< ii<< " are/ is "; for (j = 2; ii != 1; j = j + 1) { if (ii % j == 0) { for (p = 0; ii % j == 0; p = p + 1) ii = ii / j; cout<< j<<" "; } } cout<<endl; getch(); }

[Link] AM [Link]

// This C++ program displays the month // of any year and also has controls to view the // previous & the Next months. # include <iostream.h> # include <stdio.h> # include <conio.h> void main() { clrscr(); int b1,b2,o; cout<<" ENTER THE MONTH : "; cin>>b1; cout<<" ENTER THE YEAR : "; cin>>b2; a:cout<<"\n"; o = b1-1; int i,j,k=0,l=0,m=0,n=0,b3,c=0,c1,c2,c3,a[12]={31,28,31,30,31,30,31,31,30 ,31,30,31}; int ab[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; char *z[12] = {"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"}; char choice; for (o=0;o<=11;o++) { if (b1 == ab[o]) { cout<<"\n "<<z[o]; cout<<" "<<b2; } } if(b2%4==0) a[1] = 29; else a[1] = 28; if(b2>=2000) b3=b2-2000; else { b3=2000-b2; b3*=2; } if(b1==12) n=12; if(b1==1) { k=11; l=1; for(i=0;i<=k;i++) m+=a[i]; } for(i=0;i<(b1-1);i++) c+=a[i];

[Link] AM [Link]

c2=(c+b3)%7; textcolor(10); cout<<"\n\n\n\n"; cout<<" SU MO TU WE TH FR SA\n\n"; for(j=0;j<c2;j++) cout<<" "; for(j=1;j<=a[b1-1];j++) { if(j<10) cout<<" "<<j; else cout<<" "<<j; if((j+c2)%7==0) cout<<"\n\n"; } cout<<"\n"; cout<<"\n\n Use these arrow keys to display the Sequential Year or Month : \n"; cout<<"**************************************************************\n"; cout<<" | Up = Next Year | Down = Previous Year | \n"; cout<<" | Right = Next Month | Left = Next Month | \n"; cout<<"************************************************************** \n"; choice = getch(); if (choice==0) { choice = getch(); switch(choice) { case 80 : {b2-=1; goto a; break;} case 72 : {b2+=1;goto a; break;} case 75 : { if (b1!=1) b1-=1; else {b1=12; b2-=1;} goto a; break;} case 77 : { if (b1!=12) b1+=1; else {b1 = 1; b2+=1;} goto a; break;} } } getch(); }

[Link] AM [Link]

// Program to input a string and print the character with the // maximum frequency in the string. #include<iostream.h> #include<conio.h> #include<string.h> #include<process.h> #include<stdio.h> #include<string.h> main() { clrscr(); char name[40],ans; int l=0,count=0,max=0; cout<<"Enter any word "<<endl; gets(name); l = strlen(name); cout<<endl; for(int a=0;a<l;a++) { for (int b=0;b<l;b++) { if (name[a]==name[b] && name[a]!=' ') count = count+1; } if (max<count) { max=count; ans=name[a]; } count=0;} cout<<endl<<"The character with maximum frequency is "; cout<<ans<<" with occurring "<<max<<endl; getch(); return 0; }

[Link] AM [Link]

// Program to print the corresponding ASCII character #include <stdio.h> #include <fstream.h> #include <stdlib.h> #include<conio.h> main() { clrscr(); char line[512]; /* input string */ char sym; /* ASCII code number */ cout<<"Please enter the number to be factored: "; [Link](line, 512); sym = atoi(line); cout<<int(sym)<<" is the ASCII code for "; if (sym == 0) cout<<"null\n"; else if (sym == ' ') cout<<"blank\n"; else if (sym == 127) cout<<"del\n"; else if (sym >= 1 && sym <= 31) cout<<"CONTROL-\n"<< sym + 64; else if (sym >= '0' && sym <= '9') cout<<"digit \n"<< sym; else if (sym >= 'A' && sym <= 'Z') cout<<"UPPERCASE \n"<< sym; else if (sym >= 'a' && sym <= 'z') cout<<"lowercase \n"<< sym; else cout<<"punctuation mark \n"<< sym; getch(); }

[Link] AM [Link]

// Program to get the day the month starts on, and //the number of days in the month to output a calendar. //-------------------Includes -------------------#include <iostream.h> #include<conio.h> //--------------FunctionPrototypes ------------int ShowDateLine(int day, int EndDay, int BoxWidth); void ShowRestOfBox(int BoxWidth, int BoxHeight); void ShowDates(int BoxWidth); void Divider(int BoxWidth); //---------------------Main---------------------int main() { int StartDay, EndDay, day, counter, weeks; const int BoxWidth = 8, BoxHeight = 3; char end; cout << "1. Sun 2. Mon 3. Tue 4. Wed " << endl; cout << "5. Thu 6. Fri 7. Sat" << endl << endl; do { cout << "Enter the starting day: "; cin >> StartDay; if ((StartDay < 1) || (StartDay > 7)) { cout << "\aError, must be between 1 and 7.\n"; } } while ((StartDay < 1) || (StartDay > 7)); /* Error checking */ day = StartDay * -1 + 2; cout << "Enter the amount of days in the month: "; cin >> EndDay; cout << endl; weeks = (EndDay + StartDay - 2) / 7; weeks++; //----------------Draw Calendar ----------------ShowDates(BoxWidth); Divider(BoxWidth); for (counter = 0; counter < weeks; counter++) { day = ShowDateLine(day, EndDay, BoxWidth); ShowRestOfBox(BoxWidth, BoxHeight); Divider(BoxWidth); } cout<<"Press any key to continue"<<endl; getch(); } //------------------Functions -------------------int ShowDateLine(int day, int EndDay, int BoxWidth) /* Outputs a '*' then it outputs the days till it reaches the 'EndWeek' value.

[Link] AM [Link]

If day reaches the EndDay value, then it will output a space instead of a day. After each date it will output a '*', then proceed 'BoxWidth' spaces ahead. */ { int counter, EndWeek; [Link](ios::right); cout << "*"; EndWeek = day + 7; for (counter = 0; counter < 7; counter++, day++) { [Link](BoxWidth - 1); if ((day < 1) || (day > EndDay)) { cout << " "; } else { cout << day; } cout << "*"; } cout << endl; return day; } //----------------------------------------------void ShowRestOfBox(int BoxWidth, int BoxHeight) /* Outputs a '*' every 'BoxWidth' length, for a total of 8 '*'. It does that 'BoxHeight' times. */ { int countera, counterb; [Link](ios::right); for (countera = 1; countera < BoxHeight + 0; countera++) { cout << "*"; for (counterb = 0; counterb < 7; counterb++) { [Link](BoxWidth); cout << "*"; } cout << endl; } } //----------------------------------------------void ShowDates(int BoxWidth) /* Outputs the all 7 days of the week. It takes the 'BoxWidth' and outputs the day in the middle of where the box will be. */ { [Link](ios::right); [Link](BoxWidth / 2 + 2); cout << "Sun"; [Link](BoxWidth); cout << "Mon"; [Link](BoxWidth);
[Link] AM [Link]

cout << "Tue"; [Link](BoxWidth); cout << "Wed"; [Link](BoxWidth); cout << "Thu"; [Link](BoxWidth); cout << "Fri"; [Link](BoxWidth); cout << "Sat" << endl; } //----------------------------------------------void Divider(int BoxWidth) //Outputs a bar of '*' 'BoxWidth' * 7 + 1 { int length, counter; length = BoxWidth * 7 + 1; for (counter = 0; counter < length; counter++) { cout << "*"; } cout << endl; }

[Link] AM [Link]

// Program to define a class point and implement operations #include<iostream.h> #include<math.h> #include<conio.h> class Point{ public: Point(); void setPoint(float,float); void printPoint(); float getx(); float gety(); private: float x; float y; }; Point::Point(){x=0.0;y=0.0;} void Point::setPoint(float a,float b) {x=a;y=b;} void Point::printPoint() { cout<<'('<<x<<","<<y<<')'; } float Point::getx(){return x;} float Point::gety(){return y ;} void main() { clrscr(); Point p1,p2; char ch; cout<<"Initially,the points are :"; [Link](); cout<<","; [Link](); cout<<endl; [Link](3.5,4.5); [Link](7.5,9.5); cout<<"After setting the points are:"; [Link](); cout<<","; [Link](); cout<<endl; float d=0.0; d=sqrt(([Link]()-[Link]())*([Link]()-[Link]())+([Link]()-[Link]())*([Link]()-[Link]())); cout<<"d="<<d<<endl;

[Link] AM [Link]

cout<<"Enter any key to continue"; getch(); }

[Link] AM [Link]

// Program to input any string upto 500 characters // and convert the same into binary #include <iostream.h> #include <string.h> #include <stdlib.h> #include <conio.h> char *entry, letter, choice[2]; int ascii, len, binary[8], total; void prog(); int main() { clrscr(); prog(); return 0; } void prog() { entry = new char[501]; cout<<"Enter string to convert (up to 500 chars): "; [Link](entry, 500); len = strlen(entry); /* get the number of characters in entry. */ for(int i = 0; i<len; i++) { total = 0; letter = entry[i]; /* store the first letter */ ascii = letter; /* put that letter into an int, so we can see its ASCII number */ while(ascii>0) /* This while loop converts the ASCII # into binary, stores it backwards into the binary array. */ { if((ascii%2)==0) { binary[total] = 0; ascii = ascii/2; total++; /* increasing by one each time will yeild the number of numbers in the array. */ } else { binary[total] = 1; ascii = ascii/2; total++; } } total--; while(total>=0) { cout<<binary[total]; total--; }

[Link] AM [Link]

} delete[] entry; /* free up the memory used by entry */ cout<<endl<<"Do again(1 = yes, 2= no)?: "; [Link](choice,3); if(choice[0] == '1') prog(); else exit(0); /* quits the program */ }

[Link] AM [Link]

// Program to depict the usage of Binary Search Technique. // It is assumed that the list of numbers in an array is // stored in ascending order. #include<iostream.h> #include<conio.h> main() { int num[10],m,min,max,mid,pp; clrscr(); cout<<"Enter any ten numbers as elements ofan array in"; cout<<" ascending order "<<endl; for (int i=0;i<10;i++) { cin>>num[i]; } cout<<endl<<"Enter number to search "; cin>>m; cout<<endl; min = 0; max = 9; pp = -1; while ((min<= max)&&(pp == -1)) { mid = (min+max)/2; if (num[mid] == m) pp = mid; else if (num[mid]<m) min = mid + 1; else max = mid - 1; } if (pp>-1) cout<<"The element "<<m<<" lies in the array"<<" at "<<pp+1<<" position"; else cout<<"The element does not lie in the array"; cout<<endl; cout<<"Program over....press any key to continue"; getch(); return 0; }

[Link] AM [Link]

// Declaration of a Class and manipulation of member function. // Display of the result of students with computed grade of marks. #include<iostream.h> #include<conio.h> #include<string.h> #include<dos.h> class result // Declaration of the Class { private: int serialno; int rollnum; int total; int percent; public: void inputdata(int ser,int rol,int tot,int per) { serialno = ser; rollnum = rol; total = tot; percent = per; } void display(void) { clrscr(); gotoxy(30,5); cout<<"R E S U L T "; cout<<endl; // Music creation through sound command for(double d=0;d<=800;d++) {sound (d); delay(5); } nosound(); // Sound command de-activated char grade[20]; cout<<endl<<"The serial number is "<<serialno; cout<<endl<<"The roll number is "<<rollnum; cout<<endl<<"The total marks is "<<total; cout<<endl<<"The percent marks is "<<percent; if (percent<40) strcpy(grade,"Fail"); if (percent>=40 && percent<60) strcpy(grade,"Pass"); if (percent>=60 && percent<80) strcpy(grade,"First"); if (percent>=80) strcpy(grade,"Excellent"); cout<<endl<<"The grade obtained is "<<grade; cout<<endl; } }; main() { result studrecord; int ser; int rol; int tot;

[Link] AM [Link]

int per; clrscr(); cout<<"Enter the serial number"<<endl; cin>>ser; cout<<"Enter the rollnumber"<<endl; cin>>rol; cout<<"Enter the total"<<endl; cin>>tot; per=tot/5; clrscr(); [Link](ser,rol,tot,per); [Link](); cout<<endl; cout<<"Press any key to return "; getch(); clrscr();// Screen cleared for the next program output. return 0; }

[Link] AM [Link]

// Program to display Fibonaccis Heap #include <iostream.h> #include<conio.h> void main() { clrscr(); unsigned int to,a,n,n1,n2,sum; cout << "Enter the limit: n="; cin >> to; to--; n1=n2=1; a=2; sum=2; cout << "Fibonacci's numbers: " << endl; cout << "1 1 "; while(a<=to) { n=n1+n2; cout << n << " "; n1=n2; n2=n; sum=sum+n; a++; } cout << endl << endl ; cout << "Sum of all numbers= "<< sum << endl; getch(); }

[Link] AM [Link]

// Program to Calculate Polynoms //Loading the libraries #include <iostream.h> #include <math.h> #include<conio.h> //Defining variables int result=0; //here will be stored the result int *arr; //here will be stored the numbers int power; //this is the maximum power int x; //the value for "x" //Beginning the main function void main() { cout << "What s the maximum power in the polynom? : "; cin >> power; cout << endl; arr=new int[power]; //creates an array with "power" cells //Asking the user to enter the values... for(int n=0;n<power+1;n++) { cout <<"A"<<power-n<<" = "; cin >> arr[power-n]; } cout << "The polynom is: "; //Prints the polynom on the screen for(int go=power; go >-1; go--) { if(go > 0) cout <<arr[go]<<"*x^"<<go<<" + "; else cout <<arr[go]<<"*x^"<<go; } cout <<endl; cout <<"Enter value for X : "; cin >> x; //Calculating the polynom for(int cal=0; cal < power+1; cal++) { result=result+(arr[cal]*(pow(x,cal))); } cout <<" Y(x)= "<< result<<endl; // showing the result getch(); }

[Link] AM [Link]

// Program for : Matrices : To implement cell value of a defined matrix // Input: Row & Col. and Output : Cell element of the points Row, Col. #include <stdlib.h> #include <iostream.h> #include<conio.h> int main() { clrscr(); int x, y; // Loop Counter int x1, y1, repeat; // x, y Think like that if you input x = 1, y = 3 // You will output "69", that how a matrix works int matrix[4][4] = { 12, 4, 23, 6, 45, 78, 3, 57, 69, 23, 9, 2, 34, 11, 5, 99 }; cout<<"My Matrix: "<< endl << endl; for( x = 0; x < 4; x++) { for( y = 0; y < 4; y++) { cout<< matrix[x][y] << " "; } cout<<endl; } cout<< endl <<"Both x and y have a max point of 3" << endl; do { cout<< endl <<"Enter in x and y points[ x <space> y ]: "; cin>> x1 >> y1; cout<<"Point ("<< x1 <<", " << y1 <<") = " << matrix[x1][y1] << endl << endl; cout<<"Would You like Output new points (0 to quit)? "; cin>> repeat; }while( repeat != 0); cout<<endl; cout<<"Press any key to continue"; getch(); return 0; }

[Link] AM [Link]

// Program to demonstrate reversing of an input text // using a function with string arguments. #include <stdio.h> #include <iostream.h> #include<conio.h> /* strlen - return length of string s */ int strlen(char s[]) { int i; for (i = 0; s[i] != '\0'; ++i); return (i); } /* reverse - reverses order of characters in a string */ void reverse(char s[]) { char t; short i, j; for (i = 0, j = strlen(s) - 1; i < j; ++i, --j) t = s[i], s[i] = s[j], s[j] = t; } main() { char line[BUFSIZ]; /* the line of input text */ cout<<endl; cout<<"Input String to obtain in reverse"); [Link](line,BUFSIZ); reverse(line); cout<<endl; cout<<line; getch(); }

[Link] AM [Link]

// Example program to create a data file and read it as well. #include<fstream.h> #include<conio.h> main() { clrscr(); ofstream fat("[Link]"); char name[20]; char hobby[40]; int age; int i; for (i=1;i<6;i++) { cout<<"Enter the details of record "<<i; cout<<endl; cout<<"Enter name:"; cin>>name; cout<<endl<<"Enter the hobby"; cin>>hobby; cout<<endl; cout<<"Enter the age"; cin>>age; cout<<endl; fat<<name<<hobby<<age; cout<<endl; } [Link](); // opening of the file in input mode ifstream fit ("[Link]"); for(i=1;i<6;i++) { fit>>name; fit>>hobby; fit>>age; cout<<"The record number is "<<i; cout<<endl<<"The name is "<<name; cout<<endl<<"The hobby is "<<hobby; cout<<endl<<"The age is "<<age; cout<<endl; } [Link](); getch(); return 0; }

[Link] AM [Link]

// Program implementing File Operations // Assuming the class student, write functions to implement the following : //(i). Store the objects of student in a binary file. //(ii). Read the object of student from binary file and print the same on the screen. //The class student has the following format : #include<iostream.h> #include<fstream.h> #include<conio.h> #include<stdio.h> class student { int rollno; char name[20]; public: void getval() { cin>>rollno; gets(name); } void putval() { cout<<rollno; cout<<endl<<name; } }; main() { student ward; clrscr(); cout<<"Enter roll number and name of the record"<<endl; [Link](); ofstream fout; [Link]("[Link]",ios::binary); [Link]((char*)&ward,sizeof(ward)); [Link](); ifstream fin; [Link]("[Link]",ios::in|ios::binary); [Link]((char*)&ward,sizeof(ward)); cout<<endl; cout<<"The record read is "<<endl; [Link](); cout<<"Press any key to continue"; getch(); return 0; }

[Link] AM [Link]

// Program to create a data file to store any ten rollnumbers // and total marks and arrange the list in ascending order of marks // Read the file and print the new list obtained. #include<fstream.h> #include<conio.h> #include<stdio.h> main() { clrscr(); // writing records in the data file ofstream ftt("[Link]"); int marks,roll,i; for (i=0;i<3;i++) { cout<<"Enter the details of record "<<i+1; cout<<endl; cout<<"Enter [Link] "; cin>>roll; cout<<endl; cout<<"Enter the marks"; cin>>marks; cout<<endl; ftt<<roll<<"\n"<<marks<<"\n"; } [Link](); // opening of the file in input mode // for reading the records ifstream fit ("[Link]"); int rno[10],mark[10]; for(i=0;i<3;i++) { fit>>roll; fit>>marks; rno[i]=roll; mark[i]=marks; cout<<endl<<"The record number is "<<i+1; cout<<endl<<"The roll number is "; cout<<roll; cout<<endl<<"The marks are "<<marks; cout<<endl; } cout<<"Press any key to sort the data "; getch(); clrscr(); // sorting according to the marks. int rnum,mar; for(i=0;i<2;i++) { for(int j=i+1;j<3;j++) { if (mark[i]<mark[j])

[Link] AM [Link]

{ mar=mark[i]; mark[i]=mark[j]; mark[j]=mar; roll=rno[i]; rno[i]=rno[j]; rno[j]=roll; }}} [Link](); // writing sorted records. ofstream fft("[Link]"); for (i=0;i<3;i++) { fft<<rno[i]<<"\n"<<mark[i]<<"\n"; } [Link](); cout<<endl; cout<<"Records re-written in the file. Press any key to continue"; getch(); clrscr(); // reading sorted records. cout<<"The content of the list as read from the data file is : "; cout<<endl<<"(In descending order of marks )"; cout<<endl; ifstream fet ("[Link]"); for(i=0;i<3;i++) { fet>>rno[i]; fet>>mark[i]; cout<<endl<<"The record number is "<<i+1; cout<<endl<<"The roll number is "; cout<<rno[i]; cout<<endl<<"The marks are "<<mark[i]; cout<<endl; } [Link](); cout<<"Press any key to continue "; getch(); return 0; }

[Link] AM [Link]

// Program to modify a record after creation in a data file. #include<iostream.h> #include<conio.h> #include<fstream.h> #include<string.h> #include<stdio.h> class stu { protected: char na[20]; int p; public : void input(int n) { int i; remove("[Link]"); ofstream g2; [Link]("[Link]"); stu s; for(i=1;i<=n;i++) { cout<<"enter name and percentage :"; cin>>[Link]>>s.p; if (i>n) break; else { [Link]((char*)&s,sizeof(s)); } } [Link](); } void modify() { char x[20],flag; stu a; ifstream g1; [Link]("[Link]"); ofstream g2; [Link]("[Link]"); cout<<"\n\n enter the name of the person "; cin>>x; while(![Link]()) { [Link]((char*)&a,sizeof(a)); if(strcmp(x,[Link])==0) { flag='y'; cout<<"\n enter the new percentage "; cin>>a.p;

[Link] AM [Link]

} if(![Link]()) { [Link]((char*)&a,sizeof(a)); } else break; } if(flag!='y') cout<<"\n sorry no such record present "; [Link](); [Link](); remove("[Link]"); rename("[Link]" ,"[Link]"); } void display() { stu a; ifstream g3; [Link]("[Link]"); while(![Link]()) { [Link]((char*)&a,sizeof(a)); if(![Link]()) { cout<<"\n name is "<<[Link]; cout<<"\n percent is "<<a.p; } else break; } [Link](); } }; void main() { int n; clrscr(); stu s,a; cout<<"enter the number of records "; cin>>n; [Link](n); [Link](); [Link](); getch(); }

[Link] AM [Link]

[Link] AM [Link]

// Program to add and reduce two given fractions #include<iostream.h> #include<conio.h>// for clrscr() and getch() void ReadFraction(int &Num, int &Denom, int &Num2, int &Denom2) /* This function will allow the user to enter two fraction. */ { cout << "Enter the numerator for the first fraction: "; cin >> Num; cout << "Enter the denominator for the first fraction: "; cin >> Denom; cout << endl; cout << "Enter the numerator for the second fraction: "; cin >> Num2; cout << "Enter the denominator for the second fraction: "; cin >> Denom2; cout << endl; }

void Reduce(int &Num, int &Denom, int &Num2, int &Denom2) /* This function is called after ReadFraction(). This function will reduce the two fractions. Pre: Two Fractions Post: Two reduced fractions */ { int a, b, c, d, i, j = 0; a= b= c= d= Denom; Num; Denom2; Num2;

for (i = a * b; i > 1; i--) { if ((a % i == 0) && (b % i == 0)) { a /= i; b /= i; } } for (j = 50; j > 1; j--) { if ((c % j == 0) && (d % j == 0)) { c /= j;

[Link] AM [Link]

d /= j; } } Denom = a; Num = b; Denom2 = c; Num2 = d; }

void Reduce(int &Num, int &Denom) /* This function is called from AddFraction(). The fraction added in AddFraction() is reduced here. Pre: One fraction added from two Post: A reduced fraction */ { int a = 0; int b = 0; int i = 0; a = Denom; b = Num; for (i = 50; i > 1; i--) { if ((a % i == 0) && (b % i == 0)) { a /= i; b /= i; } } Denom = a; Num = b; }

void AddFraction(int &Num, int &Denom, int &Num2, int &Denom2) /* This function is called after Reduce. This function adds the two fractions Reduce() reduced Pre: Two Fractions Post: One reduced fraction */ { if (Denom != Denom2) {

[Link] AM [Link]

Num = Num * Denom2; Num2 = Num2 * Denom; Denom = Denom * Denom2; Denom2 = Denom2 * Denom; Num = Num + Num2; } else { Num = Num + Num2; } Reduce(Num, Denom); } void DisplayFraction(int &Num, int &Denom) /* This function displays the reduced and added fraction. This function is called after AddFraction() Post: Prints fraction */ { cout << "The reduced and added fraction is " << Num << "/" << Denom << endl; }

int main() { clrscr(); char an; do { int Num, Denom, Num2, Denom2 = 0; ReadFraction(Num, Denom,Num2,Denom2); Reduce(Num, Denom, Num2, Denom2); AddFraction(Num, Denom, Num2, Denom2); DisplayFraction(Num, Denom); cout << endl; cout <<"Would you like to do another fraction? "; cin >> an; cout << endl; } while ((an == 'y') || (an == 'Y')); cout<<"Press any key to continue"<<endl; getch(); return(0); }

[Link] AM [Link]

// Program to implement leap year checking using functions #include<iostream.h> #include<conio.h> void d(int ,int ,int ); //prototype of a funtion void main() { clrscr(); int x,y,z; cout<<"Enter day : "; cin>>x; cout<<"Enter month : ";cin>>y; cout<<"Enter year : ";cin>>z; d(x,y,z); getch(); } { switch (y) { case (1):cout<<"junuary";break; case (2):cout<<"fabruary";break; case (3): cout<<"march";break; case (4):cout<<"april";break; case (5):cout<<"may";break; case (6):cout<<"June";break; case (7):cout<<"july";break; case (8):cout<<"August";break; case (9):cout<<"september";break; case (10):cout<<"October";break; case (11):cout<<"november";break; case (12):cout<<"december";break; default:cout<<"Invalid month instruction"; } if (x>=32||x<=0) //Important point for day instruction cout<<"Invalid day instruction"; else cout<<x<<","; if (z<=0) cout<<"invalid year input"<<endl; else cout<<z<<endl; //function calling

void d(int x,int y,int z)

//funtion definition

[Link] AM [Link]

if(z%4==0) cout<<z<<"is a leap year"<<endl; else cout<<z<<"is not a leap year"<<endl; }

[Link] AM [Link]

// Program to implement sum of two input times. #include<iostream.h> #include<conio.h> struct time { int hrs; int mins; }; time sumtime(time,time); main() { clrscr(); time a,b,c; cout<<"enter first time in hrs:"; cin>>[Link]; cout<<"enter first time in mins:"; cin>>[Link]; cout<<"enter second time in hrs:"; cin>>[Link]; cout<<"enter second time in mins:"; cin>> [Link]; c = sumtime(a,b); cout<<"the time in hrs:"; cout<< [Link]; cout<<"the time in mins:"; cout<<[Link]; getch(); return 0; } time sumtime(time a1,time a2) { time a3; [Link] = [Link]+[Link]; [Link]= [Link]+[Link]; if ([Link]==60) { [Link]=[Link]+1; [Link]=0; } if ([Link]>60) { int h=[Link]/60; [Link]=[Link]+h; [Link]=[Link]-60; } return a3; }

[Link] AM [Link]

// Program to add any two given angles. #include<iostream.h> #include<conio.h> struct angle { int degree; int mins; }; angle sumangle(angle,angle); main() { clrscr(); angle a,b,c; cout<<"enter first angle in degree:"; cin>>[Link]; cout<<"enter first angle in mins:"; cin>>[Link]; cout<<"enter second angle in degree:"; cin>>[Link]; cout<<"enter second angle in mins:"; cin>>[Link]; c = sumangle(a,b); cout<<"the angle in degree:"; cout<<[Link]; cout<<"the angle in mins:"; cout<<[Link]; getch(); return 0; } angle sumangle(angle a1,angle a2) { angle a3; [Link] = [Link]+[Link]; [Link] =[Link]+[Link]; if ([Link]==60) { [Link]++; [Link]=0;} if ([Link]>60) { int m=[Link]/60; [Link]=[Link]+m; [Link]=[Link]-60; } return a3; }

[Link] AM [Link]

// Program to compute the lcm and hcf using class. #include<iostream.h> #include<conio.h> class work { private: int a,b; public: work() { a = 0; b = 0; } ~work() {} compute() { cout<<"Enter any two numbers"; cin>>a>>b; int p,hcf,i,lcm; p=a*b; for(i=1;i<=p;i++) { if(a%i==0 && b%i==0) hcf =i; } lcm=p/hcf; cout<<"The lcm is "<<lcm; cout<<endl; cout<<"The hcf is "<<hcf; } }; main() { clrscr(); work amit; [Link](); getch(); return 0; }

[Link] AM [Link]

// Project Programme for Hospital Database Queue array. #include #include #include #include <iostream.h> <conio.h> <string.h> <stdlib.h>

// define maximum number of patients in a queue #define MAXPATIENTS 100 // define structure for patient data struct patient { char FirstName[50]; char LastName[50]; char ID[20]; }; // define class for queue class queue { public: queue (void); int AddPatientAtEnd (patient p); int AddPatientAtBeginning (patient p); patient GetNextPatient (void); int RemoveDeadPatient (patient * p); void OutputList (void); char DepartmentName[50]; private: int NumberOfPatients; patient List[MAXPATIENTS]; }; // declare member functions for queue queue::queue () { // constructor NumberOfPatients = 0;} int queue::AddPatientAtEnd (patient p) { // adds a normal patient to the end of the queue. // returns 1 if successful, 0 if queue is full. if (NumberOfPatients >= MAXPATIENTS) { // queue is full return 0;} // put in new patient List[NumberOfPatients] = p; NumberOfPatients++; return 1;}

[Link] AM [Link]

int queue::AddPatientAtBeginning (patient p) { // adds a critically ill patient to the beginning of the queue. // returns 1 if successful, 0 if queue is full. int i; if (NumberOfPatients >= MAXPATIENTS) { // queue is full return 0;} // move all patients one position back in queue for (i = NumberOfPatients-1; i >= 0; i--) { List[i+1] = List[i];} // put in new patient List[0] = p; NumberOfPatients++; return 1;} patient queue::GetNextPatient (void) { // gets the patient that is first in the queue. // returns patient with no ID if queue is empty int i; patient p; if (NumberOfPatients == 0) { // queue is empty strcpy([Link],""); return p;} // get first patient p = List[0]; // move all remaining patients one position forward in queue NumberOfPatients--; for (i=0; i<NumberOfPatients; i++) { List[i] = List[i+1];} // return patient return p;} int queue::RemoveDeadPatient (patient * p) { // removes a patient from queue. // returns 1 if successful, 0 if patient not found int i, j, found = 0; // search for patient for (i=0; i<NumberOfPatients; i++) { if (stricmp(List[i].ID, p->ID) == 0) { // patient found in queue *p = List[i]; found = 1; // move all following patients one position forward in queue NumberOfPatients--; for (j=i; j<NumberOfPatients; j++) { List[j] = List[j+1];}}} return found;} void queue::OutputList (void) { // lists entire queue on screen int i; if (NumberOfPatients == 0) {
[Link] AM [Link]

cout << "\nQueue is empty";} else { for (i=0; i<NumberOfPatients; i++) { cout << "\n" << List[i].FirstName; cout << " " << List[i].LastName; cout << " " << List[i].ID;}}} // declare functions used by main: patient InputPatient (void) { // this function asks user for patient data. patient p; cout << "\n\nPlease enter data for new patient\nFirst name: "; [Link]([Link], sizeof([Link])); cout << "\nLast name: "; [Link]([Link], sizeof([Link])); cout << "\nSocial security number: "; [Link]([Link], sizeof([Link])); // check if data valid if ([Link][0]==0 || [Link][0]==0 || [Link][0]==0) { // rejected strcpy([Link],""); cout << "\n\nError: Data not valid. Operation cancelled."; getch();} return p;} void OutputPatient (patient * p) { // this function outputs patient data to the screen if (p == NULL || p->ID[0]==0) { cout << "\nNo patient"; return;} cout << "\n\nPatient data:"; cout << "\n\nFirst name: " << p->FirstName; cout << "\n\nLast name: " << p->LastName; cout << "\n\nSocial security number: " << p->ID;} int ReadNumber() { // this function reads an integer number from the keyboard. // it is used because input with cin >> doesn't work properly! char buffer[20]; [Link](buffer, sizeof(buffer)); return atoi(buffer);} void DepartmentMenu (queue * q) { // this function defines the user interface with menu for one department int choise = 0, success; patient p; while (choise != 6) { // clear screen clrscr();
[Link] AM [Link]

// print menu cout << "\n\n\nWelcome to department: " << q->DepartmentName; cout << "\n\nPlease enter your choise:"; cout << "\n\n1: Add normal patient"; cout << "\n2: Add critically ill patient"; cout << "\n3: Take out patient for operation"; cout << "\n4: Remove dead patient from queue"; cout << "\n5: List queue"; cout << "\n6: Change department or exit\n"; // get user choise choise = ReadNumber(); // do indicated action switch (choise) { case 1: // Add normal patient p = InputPatient(); if ([Link][0]) { success = q->AddPatientAtEnd(p); clrscr(); if (success) { cout << "\nPatient added:\n\n";} else { // error cout << "\n\nError: The queue is full. Cannot add patient:";} OutputPatient(&p); cout << "\n\nPress any key"; getch();} break; case 2: // Add critically ill patient p = InputPatient(); if ([Link][0]) { success = q->AddPatientAtBeginning(p); clrscr(); if (success) { cout << "\nPatient added:\n\n";} else { // error cout << "\n\nError: The queue is full. Cannot add patient:";} OutputPatient(&p); cout << "\n\nPress any key"; getch();} break; case 3: // Take out patient for operation p = q->GetNextPatient(); clrscr(); if ([Link][0]) { cout << "\nPatient to operate:\n\n"; OutputPatient(&p);} else { cout << "\nThere is no patient to operate.";} cout << "\n\nPress any key"; getch(); break;
[Link] AM [Link]

case 4: // Remove dead patient from queue p = InputPatient(); if ([Link][0]) { success = q->RemoveDeadPatient(&p); clrscr(); if (success) { cout << "\nPatient removed:\n\n";} else { // error cout << "\n\nError: Cannot find patient:\n\n";} OutputPatient(&p); cout << "\n\nPress any key"; getch();} break; case 5: // List queue clrscr(); q->OutputList(); cout << "\n\nPress any key"; getch(); break; }}} // main function defining queues and main menu void main () { int i, MenuChoise = 0; // define three queues queue departments[3]; // set department names strcpy (departments[0].DepartmentName, "Heart clinic"); strcpy (departments[1].DepartmentName, "Lung clinic"); strcpy (departments[2].DepartmentName, "Plastic surgery"); while (MenuChoise != 4) { // clear screen clrscr(); // print menu cout << "\n\n\nWelcome to Software City Hospital"; cout << "\n\nPlease enter your choise:\n"; for (i = 0; i < 3; i++) { // write menu item for department i cout << "\n" << (i+1) << ": " << departments[i].DepartmentName;} cout << "\n4: Exit\n"; // get user choise MenuChoise = ReadNumber(); // is it a department name? if (MenuChoise >= 1 && MenuChoise <= 3) { // call submenu for department // (using pointer arithmetics here:) DepartmentMenu (departments + (MenuChoise-1));}}}

[Link] AM [Link]

[Link] AM [Link]

// Program that reads numbers (until -1 entered or more then 1000) // into in array and sorts them in descending order. #include <iostream.h> #include <conio.h> #include <stdlib.h> typedef char String[80]; int leesgetal(String info) { int returnvalue, getal; do { cout << info; returnvalue=cscanf("%d", &getal); getch(); cout << "\n"; } while (!returnvalue); return getal; } int sort(const void *s, const void *t) { return (*(int*)s - *(int*)t); } int main(void) { clrscr(); const int aantal=1000; int getallenrij[aantal]; int teller = 0; int linepos; while (teller<1000 && getallenrij[teller-1]!=-1) { getallenrij[teller]=leesgetal("Enter array element [-1 to quit]"); teller++; } qsort(getallenrij, teller, sizeof(int), sort); linepos = teller % 23; for (teller--; teller>0; teller--) { cout << getallenrij[teller] << "\n"; if (teller % 23 == linepos) { cout << "*******"; }

[Link] AM [Link]

} cout<<endl<<"Press any key to continue"<<endl; getch(); return 0; }

[Link] AM [Link]

// to extract maximum prime digit from a number #include<iostream.h> #include<conio.h> int mprime(int); main() { int a,b; cout<<"enter a number:"; cin>>a; b=mprime(a); cout<<b; getch(); return 0; } int mprime(int c) { int n,big=0,d,count=0,i; do{ n=c%10; for(i=1;i<=n;i++) { if(n%i==0) count=count+1; if(c==2) { if(big<n) big=n; count=0; } d=d/10; } } while(c!=0); cout<<big<<"is the maximum digit number"; return big; }

[Link] AM [Link]

// Program to extract the position of any alphabet in the alphabetical series #include <ctype.h> #include <conio.h> #include <iostream.h> #define max 26 char array[max] = "\0"; void initialise() { for(int i=0; i<max; i++) { array[i] = (char)(65+i); } } int binsearch(int low, int high, int &num) { int mid = (high+low)/2; if( array[mid] == num ) { return mid; } else if( low >= high ) { return -1; } else if( num > array[mid] ) { return binsearch(mid+1, high, num); } else if( num < array[mid] ) { return binsearch(low, mid-1, num); } else return -2; } void main() { char alpha; int number; int result; clrscr(); initialise(); cout << "Enter the alphabet to search : "; cin >> alpha;

[Link] AM [Link]

number = (int)toupper(alpha); result = binsearch(0, max, number); if( result >= 0 ) { cout << "Found at index # : " << result+1; } else if( result == -1 ) { cout << "Not Found"; } else cout << "Unspecified Error"; getch(); }

[Link] AM [Link]

// Array sorting // Using Bubble Sorting Technique. // Program to input any ten numbers and print them in ascending order. #include<iostream.h> #include<conio.h> main() { int number[10],a,b,c,d; clrscr(); // clear the screen cout<<"Enter the elements of the array"<<endl; for(int i=0;i<10;i++) { cout<<"Enter number for cell "<<i<<endl; cin>>number[i]; } cout<<endl<<"Thank You ! The data entry is over"<<endl; cout<<"Press any key to continue"; getch(); cout<<"\a\a"; clrscr(); // sorting of data for(int j=0;j<10;j++) { for(int k=0;k<9;k++) { if (number[k]>number[k+1]) { a=number[k]; number[k]=number[k+1]; number[k+1]=a; } } } cout<<"The list in ascending order is "; cout<<endl; for(i=0;i<10;i++) cout<<number[i]<<"\t"; cout<<endl<<"Press any key to return to the editor"; getch(); return 0; }

[Link] AM [Link]

// Program displays the month of any year // and also has controls to view the // previous & the Next months. # include <iostream.h> # include <stdio.h> # include <conio.h> void main() { clrscr(); int b1,b2,o; cout<<" ENTER THE MONTH : "; cin>>b1; cout<<" ENTER THE YEAR : "; cin>>b2; a:cout<<"\n"; o = b1-1; int i,j,k=0,l=0,m=0,n=0,b3,c=0,c1,c2,c3,a[12]={31,28,31,30,31,30,31,31,30 ,31,30,31}; int ab[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; char *z[12] ={"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};char choice; for (o=0;o<=11;o++) { if (b1 == ab[o]) { cout<<"\n "<<z[o]; cout<<" "<<b2; } } if(b2%4==0) a[1] = 29; else a[1] = 28; if(b2>=2000) b3=b2-2000; else { b3=2000-b2; b3*=2; } if(b1==12) n=12; if(b1==1) { k=11; l=1; for(i=0;i<=k;i++) m+=a[i]; } for(i=0;i<(b1-1);i++) c+=a[i]; c2=(c+b3)%7;

[Link] AM [Link]

textcolor(10); cout<<"\n\n\n\n"; cout<<" SU MO TU WE TH FR SA\n\n"; for(j=0;j<c2;j++) cout<<" "; for(j=1;j<=a[b1-1];j++) { if(j<10) cout<<" "<<j; else cout<<" "<<j; if((j+c2)%7==0) cout<<"\n\n"; } cout<<"\n"; cout<<"\n\n Use these arrow keys to display the Sequential Year or Month : \n"; cout<<"**************************************************************\n"; cout<<" | Up = Next Year | Down = Previous Year | \n"; cout<<" | Right = Next Month | Left = Next Month | \n"; cout<<"************************************************************** \n"; choice = getch(); if (choice==0) { choice = getch(); switch(choice) { case 80 : {b2-=1; goto a; break;} case 72 : {b2+=1;goto a; break;} case 75 : { if (b1!=1) b1-=1; else {b1=12; b2-=1;} goto a; break;} case 77 : { if (b1!=12) b1+=1; else {b1 = 1; b2+=1;} goto a; break;} } } getch(); }

[Link] AM [Link]

//program implements dequeues using circular arrays. //Dequeues are queues in which elements can be //inserted/deleted from either end. #include <stdio.h> #include <conio.h> #include <math.h> #include <stdlib.h> #include <alloc.h> #define MAXSIZE 30 #define TRUE 1 #define FALSE 0 /*---------------------STRUCTUREDECLARATION -----------------------------*/ struct queue { int front,rear; int data[MAXSIZE]; }; struct queue *q; /*-----------------------------------------------------------------------*/ /*--------------------FUNCTIONDECLARATION -------------------------------*/ void insert(int); int remove(int); int empty(); void display(); /*-----------------------------------------------------------------------*/ /*--------------------GLOBAL VARIABLES -----------------------------------*/ int flag,x, count=0; /*-----------------------------------------------------------------------*/ /*------------------------MAIN-------------------------------------------*/ main() { q=(struct queue *)malloc(sizeof (struct queue)); int ch,z,i; clrscr(); q->front=0; q->rear=0; for (i=0; i<MAXSIZE; i++) q->data[i]=-1; do { cout<<"\n"; cout<<"\n 1. Insert an element to the left."; cout<<"\n 2. Insert an element to the right."; cout<<"\n 3. Delete an element from the left."; cout<<"\n 4. Delete an element from the right."; cout<<"\n 5. Display current status of the dequeue."; cout<<"\n 6. Exit."; cout<<"\n Enter choice:";

[Link] AM [Link]

cin>>ch; switch(ch) { case 1 : insert(1); display(); break; case 2 : insert(2); display(); break; case 3 : z=remove(1); cout<<"\n The element deleted is: "<< z; display(); break; case 4 : z=remove(2); cout<<"\n The element deleted is:"<< z; display(); break; case 5 : display(); break; case 6 : exit(1); } }while (ch!=7); getch(); } /*-----------------------------------------------------------------------*/ /*----------------------INSERT ELEMENT -----------------------------------*/ void insert(int flag) { int value; clrscr(); printf("\n Enter the element to be inserted into the queue:"); scanf("%d", &value); count++; if (flag==1) { if (count==1) { q->front==0; q->rear=0; } else if (q->front==0 && count>1 && q->data[MAXSIZE-1]==-1) q->front=MAXSIZE-1; else if (q->front==0 && q->data[MAXSIZE-1]!=-1) { printf("\n Queue full."); getch(); return; } else q->front--; q->data[q->front]=value; return;
[Link] AM [Link]

} else if (flag==2) { if (count==1) { q->rear=0; q->front=0; } else if (q->rear==MAXSIZE-1 && q->data[0]==-1) q->rear=0; else if (q->rear==MAXSIZE-1 && q->data[0]!=-1) { printf("\n Queue full."); getch(); return; } else q->rear++; q->data[q->rear]=value; return; } } /*-----------------------------------------------------------------------*/ /*------------------------DELETE ELEMENT ---------------------------------*/ int remove (int flag) { if (empty()) { printf("\n Sorry, queue is empty."); getch(); return(0); } if (flag==1) { if (count==1) { x=q->data[q->front]; q->data[q->front]=-1; q->front=q->rear; count--; return(x); } if (q->front==MAXSIZE-1) { x=q->data[q->front]; q->data[q->front]=-1; q->front=0; count--; return(x); } x=q->data[q->front]; q->data[q->front]=-1; q->front++;
[Link] AM [Link]

count--; return(x); } else if (flag==2) { if (count==1) { x=q->data[q->rear]; q->data[q->rear]=-1; q->front=q->rear; count--; return(x); } if (q->rear==0) { x=q->data[q->rear]; q->data[q->rear]=-1; q->rear=MAXSIZE-1; count--; return(x); } x=q->data[(q->rear)]; q->data[q->rear]=-1; q->rear--; count--; return(x); } } /*-----------------------------------------------------------------------*/ /*------------------------EMPTY QUEUE------------------------------------*/ int empty() { if (q->front==q->rear && q->data[q->front]==-1) return(TRUE); else return(FALSE); } /*-----------------------------------------------------------------------*/ /*-------------------------DISPLAYQUEUE---------------------------------*/ void display() { int i,fl=0; printf("\n Total number of elements in queue = %d",count); if (count==0) return; else { printf("\n The queue is:"); { if (count==1) { printf(" %d ",q->data[q->front]);
[Link] AM [Link]

return; } i=q->front; while ( i<=MAXSIZE-1) { fl=0; if (i==q->rear) { printf (" %d ", q->data[q->rear]); fl=1; break; } if (q->data[i]!=-1) { printf(" %d ",q->data[i]); } i++; } if (fl==0) { i=0; while (i<=q->rear) { if (q->data[i]!=-1) { printf(" %d ",q->data[i]); } i++; } cout<<endl; cout<<"Press any key to continue"<<endl; getch(); } } } }

[Link] AM [Link]

// Adding elements of two given arrays into the third array. # include<iostream.h> # include <conio.h> void main() { clrscr(); int a[10],b[10],c[10],s,i; cout<<"enter the 10 numbers"; for(i=0;i<10;i++) { cin>>a[i]; } // creating second array cout<<"enter the 10 numbers"; for (i=0;i<10;i++) { cin>>b[i]; } //adding the sum of two arrays into a new array for(i=0;i<10;i++) { s = a[i] + b[i]; c[i] = s; } //printing of an array cout<<endl; cout<<"Printing array A"<<endl; for (i=0;i<10;i++) { cout<<a[i]<<" "; } cout<<endl; cout<<"Printing array B"<<endl; for ( i= 0;i<10;i++ ) { cout<<b[i]<<" "; } cout<<endl; cout<<"Printing array C"<<endl; for (i=0;i<10;i++) { cout<<c[i]<<" "; } getch(); }

[Link] AM [Link]

[Link] AM [Link]

// Program to print the sum of the following series: // 1 + (1+2)+(1+2+3)+......N where N is the input. #include<iostream.h> #include<conio.h> int series(int); main() { clrscr(); int term, sum =0; cout<<"Enter the value of N"<<endl; cin>>term; sum=series(term); cout<<"The sum of the series of "<<term<<" terms is "<<sum<<endl; cout<<"Press any key to continue"<<endl; getch(); return 0; } int series(int num) { int s=0,ss=0, i,j; for(i=1;i<=num;i++) { ss=0; for(j=1;j<=i;j++) ss=ss+j; s=s+ss; } return s; }

[Link] AM [Link]

// Program to convert binary to decimal using a function. #include <math.h> #include <conio.h> #include <stdlib.h> #include <iostream.h> int binary[16] = {0}; //Store binary digits //GET BINARY INPUT FROM USERS void get_input(int binary[], int &counter) { char digit[2] = {'\0'}; //Store single digits cout << "Enter binary number: "; //Take inputs until the user does not press enter key while( digit[0] != '\r' ) { digit[0] = getche(); //Store the digit to binary number only if it is not enter key if( digit[0] != '\r' ) { binary[counter] = atoi(digit); counter++; } } } //CONVERT THE ENTERED BINARY NUMBER TO DECIMAL void convert_BtoD(int binary[], int &counter) { unsigned int decimal = 0; //Stores the decimal equivalent double power = 0; //The power to raise 2 //Start with the last digit entered, move left and increase power for(int n=(counter-1); n>=0; n--) { decimal += (binary[n]*pow(2,power)); power++; } cout << endl << decimal; } void main() { int counter = 0; clrscr(); get_input(binary, counter);

[Link] AM [Link]

convert_BtoD(binary, counter); cout<<endl; cout<<"Press any key to continue"; getch(); }

[Link] AM [Link]

// Program to convert any entered decimal number into binary. #include <conio.h> #include <stdlib.h> #include <string.h> #include <iostream.h> void convert_DtoB(int); void show_answer(int[],int); //FUNCTION THAT CONVERTS DECIMAL NUMBER TO BINARY void convert_DtoB(int decimal) { int remainder = 0; int int counter = 0; binary[16] = {0}; //array to store the binary equivalent

while( decimal != 1 ) { remainder = decimal % 2; //calculate the remainder decimal = (int)(decimal / 2); //calculate the leftover number binary[counter] = remainder; counter++; } binary[counter] = decimal; show_answer(binary,counter); } //FUNCTION THAT DISPLAYS THE BINARY NUMBER void show_answer(int answer[], int counter) { //traverses the array backwards for(int n=counter; n>=0; n--) { cout << answer[n]; } } void main() { int number = 0; clrscr(); cout << "Enter a Decimal number please....: "; cin >> number; number = abs(number); //To avoid negative entries cout<<endl; cout<<"The binaray equivalent is "; convert_DtoB(number); getch(); //store remainder as binary digit

//store the left over number as binary digit //display the binary number

[Link] AM [Link]

[Link] AM [Link]

// Program to create two arrays of 3x4 and compute their sum in a // new array. Display the new array so obtained. #include<iostream.h> #include<conio.h> main() { int a[3][4],b[3][4],c[3][4],i,j; // creation of the array for(i=0;i<3;i++) { for(j=0;j<4;j++) { cout<<"enter a number for the array a and b "; cin>>a[i][j]>>b[i][j]; } } // print the array a for(i=0;i<3;i++) { for(j=0;j<4;j++) { cout<<a[i][j]<<" "; } cout<<"\n"; } //print array b for(i=0;i<3;i++) { for(j=0;j<4;j++) { cout<<b[i][j]<<" "; } cout<<"\n"; } // get the sum in a new array for(i=0;i<3;i++) { for(j=0;j<4;j++) { c[i][j]=a[i][j]+b[i][j]; } } // display array c cout<<"The array c is "<<endl; for(i=0;i<3;i++) { for(j=0;j<4;j++) { cout<<c[i][j]<<" "; } cout<<endl; }

[Link] AM [Link]

getch(); return 0; }

[Link] AM [Link]

[Link] AM [Link]

// Program to assign names of any four subjects and check if it is present // using double dimensional arrays. #include <iostream.h> #include <string.h> #include <conio.h> //Global varibales char str[][20]={"english","physics","chemistry","history"}; void find(char *);//find function void main() { clrscr(); char st[20]; cout<<"Enter the name of any subject to find here;"<<endl; cin>>st; find(st); } void find(char *s) { int i,flag=0; for(i=0;i<3;i++) { if(strcmp(s,str[i])==0) { flag=1; cout<<"FOUND"; getch(); } } if(flag==0) {cout<<"NOTFOUND"; cout<<"\ You are the Trespasser";} getch(); }

[Link] AM [Link]

// Program to count the number of words within an entered string // and also print the string in reverse. #include<iostream.h> #include<conio.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { clrscr(); int s=0; char a[25]; cout<<"enter a string"; gets(a); int l=strlen(a); for(int i=l;i>=0;i--) { cout<<a[i]; } for(int j=0;j<l;j++) {if(a[j]==' ') {s=s+1; } } cout<<"number of words"<<s+1; getch(); }

[Link] AM [Link]

// Program to implement calculation for +, -, * and / // Input two numbers with operator in between to obtain the computation #include <iostream.h> #include <stdio.h> #include <conio.h> float result,a,b; // declare result a and b char c; // declare c char yn; // declare yn int sum() { textcolor(RED); // change the text color red cprintf("Enter Operation eg. 8+5 : "); //output statement for color cin >> a >> c >> b; // gets a b and c in one if (c == '+') { result = a + b; } if (c == '-') { result = a - b; } if (c == '*') { result = a * b; } if (c == '/') { result = a / b; } textcolor(GREEN); // guess cprintf("Answer: "); cout << result; // same as textcolor(LIGHTBLUE); // guess again cprintf("\n\rDo You Wan't To Do Another Sum?Y/N "); cin >> yn; if (yn != 'y') // if yn is different from y... { return 0; // exit the program } else; clrscr(); // clears the screen

[Link] AM [Link]

sum(); //restarts itself } int main() { clrscr(); sum(); }

[Link] AM [Link]

// Program which calculates the day of the week for any // given date & month of the year 2002. #include<stdio.h> #include<conio.h> #include<iostream.h> void main() { clrscr(); int opt,date,day; char b; cout<<"****A program to find out the day of the week for any date of the year 2002****\n\n"; cout<<"[Link]\[Link]\[Link]\[Link]\[Link]\[Link]\[Link]\[Link]\[Link]\[Link]\n11.N ovember\[Link]\n"; a: cout<<"\nEnter the value of the month:"; cin>>opt; cout<<"\nEnter the date of the month:"; cin>>date; switch(opt) { case 1: if(date<=31) {day=(8+date)%7;} else cout<<"\nFor u'r kind information january has only 31 days.\n"; break; case 2: if(date<=28) {day=(11+date)%7;} else cout<<"\nFor u'r kind information february has only 28 days.\n"; break; case 3: if(date<=31) {day=(11+date)%7;} else cout<<"\nFor u'r kind information march has only 31 days.\n"; break; case 4: if(date<=30) {day=(7+date)%7;} else cout<<"\nFor u'r kind information april has only 30 days.\n"; break; case 5: if(date<=31) {day=(9+date)%7;} else cout<<"\nFor u'r kind information may has only 31 days.\n"; break;

[Link] AM [Link]

case 6: if(date<=30) {day=(12+date)%7;} else cout<<"\nFor u'r kind information june has only 30 days.\n"; break; case 7: if(date<=31) {day=(7+date)%7;} else cout<<"\nFor u'r kind information july has only 31 days.\n"; break; case 8: if(date<=31) {day=(10+date)%7;} else cout<<"\nFor u'r kind information august has only 31 days.\n"; break; case 9: if(date<=30) {day=(6+date)%7;} else cout<<"\nFor u'r kind information september has only 30 days.\n"; break; case 10: if(date<=31) {day=(8+date)%7;} else cout<<"\nFor u'r kind information october has only 31 days.\n"; break; case 11: if(date<=30) {day=(11+date)%7;} else cout<<"\nFor u'r kind information november has only 30 days.\n"; break; case 12: if(date<=31) {day=(6+date)%7;} else cout<<"\nFor u'r kind information december has only 31 days.\n"; break; } if(day==0) {cout<<"\nIts SUNDAY.\n";} if(day==1) {cout<<"\nIts MONDAY.\n";} if(day==2) {cout<<"\nIts TUESDAY.\n";} if(day==3)
[Link] AM [Link]

{cout<<"\nIts WEDNESDAY.\n";} if(day==4) {cout<<"\nIts THURSDAY.\n";} if(day==5) {cout<<"\nIts FRIDAY.\n";} if(day==6) {cout<<"\nIts SATURDAY.\n";} cout<<"\n****************************************************\n"; cout<<"\nWould u like to continue?[y/n]:"; cin>>b; if(b=='y'||b== 'Y') goto a; else getch(); }

[Link] AM [Link]

// Program to Identify the day on a particular date #include<iostream.h> #include<stdio.h> #include<conio.h> #define STD_DD 1 #define STD_MM 1 #define STD_YYYY 0001 #define STD_DAY "Sunday" #define LEAP_YR 366 #define NOT_LEAP 365 unsigned int dd, mm, yyyy, y; void input(void); unsigned int select_days(unsigned int); void printday(unsigned int); void main(void) { unsigned int daylimit, day = 1, d, m; clrscr(); cout<<" This program tells you the day of the date typed in.\n"; input(); for (y = STD_YYYY; y <= yyyy; y++) { for (m = 1; m <= 12; m++) { daylimit = select_days(m); for (d = 1; d <= daylimit; d++) { if (day == 8) day = 1; if ((d == dd) && (m == mm) && (y == yyyy)) break; ++day; } if ((d == dd) && (m == mm) && (y == yyyy)) break; } if ((d == dd) && (m == mm) && (y == yyyy)) break; }

[Link] AM [Link]

cout<<endl; cout<<"The day on the date "<<mm<<" "<< dd<<" "<<yyyy<<" is "; printday(day); getche(); } void input(void) { cout<<"\n Type in the date (mm dd yyyy) : "; cin>>mm; cin>>dd; cin>>yyyy; if ((mm <= 0) || (mm > 12)) { do { printf(" Type in the month again : "); scanf("%d",&mm); } while ((mm <= 0) || (mm > 12)); } if ((dd <= 0) || (dd > 31)) { do { printf(" Type in the day date again : "); scanf("%d",&dd); } while ((dd <= 0) || (dd > 31)); } if ((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11) && (dd == 31)) { printf(" Date can't be greater than 30 for this month!\n"); do { printf(" Type in the day date again : "); scanf("%d",&dd); } while ((dd > 30) || (dd <= 0)); } else if ((mm == 2) && (dd > 29)) { printf(" Date can't be greater than 29 for this month!\n"); do { printf(" Type in the day date again : "); scanf("%d", &dd); }
[Link] AM [Link]

while ((dd > 29) || (dd <= 0)); } if ((yyyy % 4 != 0) && (mm == 2) && (dd == 29)) { printf(" Date of 29 in the month 2 is only possible in the leap years!\n"); do { printf(" Type in the day date again : "); scanf("%d", &dd); } while ((dd > 28) || (dd <= 0)); } if (yyyy <= 0) { do { printf(" Type in the year : "); scanf("%d",&yyyy); } while (yyyy <= 0); } } unsigned int select_days(unsigned int m) { switch (m) { case 2: if (y % 4 != 0) return(28); else return(29); case 1 : case 3 : case 5 : case 7 : case 8 : case 10: case 12: return(31); default: return(30); } } void printday(unsigned int day) { switch (day) {
[Link] AM [Link]

case 1: printf("Sunday.\n"); break; case 2: printf("Monday.\n"); break; case 3: printf("Tuesday.\n"); break; case 4: printf("Wednesday.\n"); break; case 5: printf("Thursday.\n"); break; case 6: printf("Friday.\n"); break; case 7: printf("Saturday.\n"); break; } }

[Link] AM [Link]

// Program to create a doubly linked list, // to add an item(in front,in middle or in end), // to delete an element(in front,in middle or in end) // and to display to elements in the nodes. #include<iostream.h> #include<conio.h> #include<stdlib.h> class dlink { struct link { int data; link *prev; link *next; }*head,*trav,*tptr; int p,flag,a,p1,b; public: void creation(int); void additem(int); void deletion(); void display(); dlink() { head=NULL; } }; void dlink::creation(int i) { link *newlink=new(link); if(head==NULL) { newlink->data=i; newlink->prev=NULL; newlink->next=NULL; head=newlink; } else { trav=head; while(trav->next!=NULL) { trav=trav->next; } newlink->prev=trav; trav->next=newlink; newlink->data=i; newlink->next=NULL; }

[Link] AM [Link]

} void dlink::additem(int i) { if(head==NULL) cout<<"\n DOUBLEY LINKED LIST NOT CREATED"; else { cout<<" [Link], [Link], [Link] \n"; cout<<" Your option : "; cin>>p; link *newlink=new(link); switch(p) { case 1: newlink->data=i; newlink->next=head; head->prev=newlink; newlink->prev=NULL; head=newlink; break; case 2: cout<<"\nEnter the no. after which to be added : "; cin>>a; trav=head; tptr=head; while(trav->data!=a) { tptr=trav->next->next; trav=trav->next; } newlink =new(link); newlink->prev=trav; newlink->next=tptr; newlink->data=i; tptr->prev=newlink; trav->next=newlink; break; case 3: trav=head; while(trav->next!=NULL) { trav=trav->next; } trav->next=newlink; newlink->prev=trav; newlink->data=i; newlink->next=NULL; break; } } } void dlink::deletion()
[Link] AM [Link]

{ if(head==NULL) cout<<"\n DOUBLEY LINKED LIST NOT CREATED "; else { cout<<" 1. Deletion in front, 2. Middle, [Link] \n"; cout<<"option : "; cin>>p1; switch(p1) { case 1: if(head!=NULL) { trav=head; trav=trav->next; trav->prev=NULL; head=trav; } else cout<<"\n doubley linked list not created "; break; case 2: if(head!=NULL) { cout<<"enter the element to be deleted : "; cin>>b; trav=head; while(trav->data!=b) { tptr=trav; trav=trav->next; } tptr->next=trav->next; trav->next->prev=tptr; } else cout<<"\n doubley linked list not created "; break; case 3: trav=head; while(trav->next!=NULL) { tptr=trav; trav=trav->next; } tptr->next=NULL; trav=tptr; break; } } } void dlink::display()
[Link] AM [Link]

{ if(head==NULL) cout<<"\n NO ELEMENTS IN THE DOUBLEY LINKED LIST "; else { cout<<" \n\n\t ELEMENTS IN THE DOUBLEY LINKED LIST ARE GIVEN BELOW : \n\n\n\n\t "; trav=head; while(trav->next!=NULL) { cout<<trav->data<<" <==> "; trav=trav->next; } cout<<trav->data<<" <==> NULL"; } } void main() { dlink d; int ch,x,y; do { clrscr(); cout<<" \n\n\t\t PROGRAM FOR DOUBLEY LINKED LIST "; cout<<"\n\n\t Menu \n\n"; cout<<"\n\t\t 1. Creation "; cout<<"\n\t\t 2. Adding an element "; cout<<"\n\t\t 3. Deleting an element "; cout<<"\n\t\t 4. Display"; cout<<"\n\t\t 5. Exit \t"; cout<<"Opion : "; cin>>ch; switch(ch) { case 1: do { cout<<"\nEnter a +ve no. enter -ve no. to stop the creation : "; cin>>x; if(x>0) [Link](x); } while(x>0); break; case 2: cout<<"\n\nEnter the element : "; cin>>y; [Link](y); getch(); break; case 3:
[Link] AM [Link]

[Link](); getch(); break; case 4: [Link](); getch(); break; case 5: exit(0); break; default: cout<<"\n Enter the option between 1 and 5 :"; break; } } while(ch!=5); }

[Link] AM [Link]

// PROGRAM Inputting NINE INPUTS AND TREATS THE // INPUTS AS COMPONENTS OF THREE DIMENSIONAL MATRIX AND CALCULATES THE // // DETERMINANT OF THE MATRIX. #include <stdio.h> #include <conio.h> // HEADER FILES #include <iostream.h> void main() { clrscr(); int matrix[4][4]; // DECLARATION OF ARRAY AND VARIABLES. int count,count1,result; int x,y; for (count1=1;count1<=3;count1++) // NESTED FOR LOOPS TO TAKE INPUTS // FROM THE USER. { for (count=1;count<=3;count++) { clrscr(); gotoxy(21,13); cout << "PLEASE ENTER A INTEGER : "; cin >> matrix[count][count1]; // INPUT IS STORED IN DIFFERENT // ADDRESSES OF THE ARRAY. } } // THE FOLLOWING STEPS PERFORM DIFFERENT CALCULATIONS TO CALCULATE THE // DETERMINANT count = matrix[1][1]*((matrix[2][2]*matrix[3][3])-(matrix[3][2]*matrix[2][3])); count1 = matrix[2][2]*((matrix[1][2]*matrix[3][3])-(matrix[3][2]*matrix[1][3])); result = matrix[3][3]*((matrix[1][2]*matrix[2][3])-(matrix[2][2]*matrix[1][3])); result = count - count1+result; gotoxy(21,15); cout << "THE DETERMINANT OF MATRIX IS :"<<result; // SHOWS THE DETERMINANT getch(); } // END OF FUNCTION

[Link] AM [Link]

// Program implementing File Streaming : // Storing array of numbers in a data file #include <stdlib.h> #include <iostream.h> #include <fstream.h> int main() { ifstream fin; ofstream fout;

// File Pointers

int array[4] = { 3, 76, 5, 12 }; // Array of data to be saved int x; // Loop Counter [Link]("[Link]"); // Create file for( x = 0; x < 4; x++ ) { fout << array[x] << endl; // Write array data to file } cout<<"Data Has Been Writen..." << endl; // [Link] can be found // @ C: getch(); [Link](); // Closes file return 0; }

[Link] AM [Link]

// Program to implement Calculator functions for : +, -, *, /, ^ #include <iostream.h> #include <conio.h> float inputOne, inputTwo, answer; char operator_, yn; int main() { textcolor(LIGHTBLUE); while (yn != 'n') { clrscr(); cout << "First number + - / * ^ second number\n"; cin >> inputOne >> operator_ >> inputTwo; if (operator_ == '+') answer = inputOne + inputTwo; if (operator_ == '-') answer = inputOne - inputTwo; if (operator_ == '*') answer = inputOne * inputTwo; if (operator_ == '/') { if (inputTwo == 0) { cout << "Cannot divide by 0"; } else answer = inputOne / inputTwo; } if (operator_ == '^') { answer = inputOne; for (int i=2; i<=inputTwo; i++) answer = answer * inputOne; } cout << endl; cout << inputOne << " " << operator_ << " "; cout << inputTwo << " = " << answer; cout << "\n\nSolve another? <yn> "; cin >> yn; cout << "\n"; } return 0;

[Link] AM [Link]

[Link] AM [Link]

// Program to compute surface area of cone, cylinder, vol. of cone etc. #include <iostream.h> #include <conio.h> #include <stdlib.h> void SAofcone(); void SAofCylinder(); void Volumeofcone(); void beginning(); void SAofCone() { clrscr(); cout<<"This program calculates the SA of a cone. it uses 3.14 for pi."<<endl; float pi; pi= 3.14; float r; cout<< "Enter the radius of the base of the cone?"<<endl; cin>> r; float basearea; basearea= (r*r*pi); float height; cout<<"Enter the height of the cone?"<<endl; cin>> height; float SA; SA= (basearea)+(pi*r*height); cout<<endl; cout<<"The answer is:"; cout<< SA; system("pause"); beginning(); } void SAofCylinder() { cout<<"This program calculates the surface area of a cylinder,"<<endl; cout<<"it uses 3.14 for pi."<<endl; float r; cout<<"Enter the radius of the base?"<<endl; cin>> r; float pi; pi= 3.14; float height; cout<<"Enter the height of the circle?"<<endl; cin>>height; float circumfrence; circumfrence= r*2*pi; float SA; SA= 2*(3.14)*(r*r)+2*(3.14)*(r)*(height); cout<<"The compute result is approximately:"; cout<< SA; cout<<""<<endl; system("pause"); beginning();

[Link] AM [Link]

} void Volumeofcone() { cout<<"This program calculates the volume of a cone. it used 3.14 for pi."<<endl; cout<<""<<endl; float r; cout<<" Enter the radius of the base?"<<endl; cin>> r; float pi; pi= 3.14; float height; cout<<"Enter the height of the cone?"<<endl; cin>> height; float pirsq; pirsq= pi*r; float volume; volume= (.333333)*(pi)*(r*r)*(height); cout<<"Enter the volume of the cone is approxmately:"; cout<< volume; cout<<""<<endl; system("pause"); beginning(); } int main(void) { clrscr(); beginning(); } void beginning() { cout<<"Press any key to continue"<<endl; getch(); clrscr(); cout<<"------------------------------------\n"; cout<<"----**OPTIONS**--------------------\n"; cout<<"------1. find the SA of a cone------\n"; cout<<"------2. find the SA of a cylinder--\n"; cout<<"------3. find the volume of a cone--\n"; cout<<"------------------------------------\n"; cout<<"----- 4. Exit- ----------------------"<<endl; int choice = 0; cin>> choice; if (choice == 1) SAofCylinder(); if (choice == 2) SAofCone(); if (choice == 3) Volumeofcone(); if (choice == 4) exit(0);
[Link] AM [Link]

[Link] AM [Link]

// Program for computation of: //1). Natural Log (Ln) //2). Log with Base 10(Log10) //3).Log of your desired Base (LogA^x) #include<iostream.h> #include<iomanip.h> #include<stdlib.h> #include<dos.h> #include<conio.h> #include<math.h> class logarithem { protected: long ans; public: logarithem():ans(0) { /* cout<<"Enter the value of 'X':"; cin>>ans; */ } double loga(double); double ln(double x); double checking(double); }; double logarithem::loga(double b) { double LOG10=0,c; c=ln(b); LOG10=c/2.30258509299404; return LOG10; } double logarithem:: ln(double x) { double lnX=0.000001,check; do{ lnX=lnX-(exp(lnX)-x)/exp(lnX); check=checking(lnX); }while(check!=0); return lnX; } double logarithem::checking(double x)

[Link] AM [Link]

{ static double x1=0; double x2; if(x1==0) { x1=x; return 1; } else { x2=x1-x; if(x2<0) x2*=-1; x1=x; return x2; } } void main() { clrscr(); logarithem a; double b=0,k=0; int opt1; char ch; clrscr(); highvideo(); textcolor(BLACK); textbackground(3); one: cout<<"\n1. For Natural Log (ln) "; cout<<"\n2. For Log of Base 10"; cout<<"\n3. For Log of x with Base a, Log a^x = Logx/Loga"; cout<<"\n4. For Exit"; cout<<"\n "; cout<<"\n\n\n\tEnter Your Option:- "; cin>>opt1; switch(opt1) { case 2: cout<<"\n\nEnter the value of X : "; cin>>b; cout<<"\n\n\t( Log_10^"<<b<< " is "<<[Link](b)<<" )"; cout<<endl<<"\n\tPress any key to go back...."; ch=getch();
[Link] AM [Link]

if(ch=='\r') clrscr(); goto one; case 1: cout<<"\n\nEnter the value of X"<<"\t"; cin>>b; cout<<"\n\n\t( Ln "<<b<<" : "<<[Link](b)<<" )"; cout<<endl<<"\n\tPress any key to go back...."; ch=getch(); if(ch=='\r') clrscr(); goto one; case 3: cout<<"\n\nEnter the value of a :"<<"\t"; cin>>b; cout<<"\nEnter the value of x :"<<"\t"; cin>>k; cout<<"\n\n\t( Log a^x = Logx/Loga "<<b<<" : "<<[Link](k)/[Link](b)<<" )"; cout<<endl<<"\n\tPress any key to go back...."; ch=getch(); if(ch=='\r') clrscr(); goto one; case 4: delay(100); exit(0); default: cout<<"\n\n\tPlease! Enter the options shown above ..."; cout<<endl<<"\n\tPress any key to go back...."; ch=getch(); if(ch=='\r') clrscr(); goto one; } }

[Link] AM [Link]

// Program to implement calculation on any entered two numbers. #include <iostream.h> #include <conio.h> float a; float b; float result; int op; int option; int main() { do { cout << "Enter First Number \n"; cin >> a; // Input cout << "Enter Second Number \n"; cin >> b; cout << "Please enter an Option..\n"; cout << "[1] Add \n"; cout << "[2] Substract \n"; cout << "[3] Multiply \n"; cout << "[4] Devide \n "; cin >> op; // The keybord input is passed to variable 'op' switch (op)// switch is similar to Select Case in VB { case 1 : // Case Addition result=a+b; break; case 2 : //Case Substraction result=a-b; break; case 3 : // Case multiplication result=a*b; break; case 4 : // Case Division result=a/b; } cout <<"The Result is..= " << result << "\n\n"; //Display Result and Skipping two Lines cout << "Enter an Option..\n"; cout << "[0] Exit.\n"; cout << "[1] Continue. \n"; cin >> option; // Do While loop Ends Here } while (option==1); // If option is 1 ie 'Continue' the above code is Looped else ( option<>1 ) it is Escaped from Loop return 0;// the ' main' function returns value 0 }

[Link] AM [Link]

//Program will ask the user for a starting number //and an ending number and compute the sum of the numbers in between. #include<iostream.h> #include<conio.h> void main() { char Answer; do{ int Number1, Number2; long Total = 0; clrscr(); gotoxy(25,11); cout<<"Enter starting number: "; cin>>Number1; gotoxy(25,12); cout<<"Enter ending number: "; cin>>Number2; for(int i = Number1;i <= Number2; i++) { Total += i; } clrscr(); gotoxy(25,11); cout<<"The sum of the integers from "<<Number1<<" to " <<Number2<<" is "<<Total<<"."; gotoxy(25,12); cout<<"Repeat Y/N?: "; cin>>Answer; }while( Answer =='Y' || Answer == 'y'); clrscr(); gotoxy(25,11); cout<<"-press enter to quit-"; getch(); }

[Link] AM [Link]

// Program implementing all four types of sorting of a string. #include <iostream.h> #include <string.h> #include <conio.h> void MinSort(char*, int); void BubbleSort(char*, int); void InsertionSort(char*, int); void ShellSort(char*, int); int main() { clrscr(); char cr[] = "skdmrsrjsrkpmnoprkseef"; cout << "Data before sorting is "<<cr << endl; ShellSort(cr, strlen(cr)); cout <<"Now the change is "<< cr << endl; getch(); return 0; } // Complexity: n^2 void MinSort(char* array, int n) { int i, j, temp_index; char min; for (i=0; i < n-1; ++i) { temp_index = i; min = array[i]; for (j = i+1; j < n; ++j) { if (array[j] < min) { temp_index = j; min = array[j]; } } array[temp_index] = array[i]; array[i] = min; } } // Complexity: n^2 void BubbleSort(char* array, int n) {

[Link] AM [Link]

int i, j; char temp; for (i = 0; i < n-1; ++i) for (j = i+1; j > 0; --j) if (array[j] < array[j-1]) { temp = array[j]; array[j] = array[j-1]; array[j-1] = temp; } } // Complexity: n^2 void InsertionSort(char* array, int n) { int i, j; char temp; for (i=1; i < n; ++i) { temp = array[i]; j = i-1; while ((j >= 0) && (temp < array[j])) { array[j+1] = array[j]; j--; } array[j+1] = temp; } } // Complexity: n^1.2 void ShellSort(char* array, int n) { int i, j, k, s, gap_cnt; char temp; int gaps[5]; gaps[0] = 9; gaps[1] = 5; gaps[2] = 3; gaps[3] = 2; gaps[4] = 1; for (gap_cnt = 0; gap_cnt < 5; gap_cnt++) { k = gaps[gap_cnt]; s = -k; for (i = k; i < n; ++i)

[Link] AM [Link]

{ temp = array[i]; j = i-k; if (s == 0) { s = -k; s++; array[s] = temp; } while (temp < array[j] && j >= 0 && j <= n) // + Bound checking { array[j+k] = array[j]; j = j-k; } array[j+k] = temp; } } }

[Link] AM [Link]

// Program implementing Bubble Sort for an entered range of numbers. // Using passing of array for sorting through functions. #include <iostream.h> #include <conio.h> int bubbleInput(int n); double bubbleSort(double a[], int n); double bubblePass(double a[], int n); double bubbleSwap(double& i, double& j); double bubbleOutput(double a[], int n); int main () { int n; clrscr(); cout<<"Please do not exceed above 100."<<endl; cout<<"How many numbers would you like to sort: "; cin>>n; bubbleInput(n); cout<<endl; return 0; } int bubbleInput(int n) { double a[100]; for (int i=0; i<n; i++) { cout<<"Please enter a number to sort: "; cin>>a[i]; } bubbleSort(a, n); bubbleOutput(a, n); return 0; } double bubbleSort(double a[], int n) { for (int i=0; i<n; i++) bubblePass(a,n); return 0; } double bubblePass(double a[], int n) { for (int i=0; i<n-1; i++) if (a[i] > a[i+1]) bubbleSwap(a[i], a[i+1]);

[Link] AM [Link]

return 0; } double bubbleSwap(double& i, double& j) { double temp = i; i = j; j = temp; return 0; } double bubbleOutput(double a[], int n) { for (int i=0; i<n; i++) { cout << a[i] << " "; } cout<<" "<<endl; cout<<"Press any key to continue"<<endl; getch(); return 0; }

[Link] AM [Link]

// Program to conduct: Array sorting // Using Insertion Sorting Technique. // Program to input any five numbers and print them in descending order. #include<iostream.h> #include<conio.h> main() { clrscr(); int number[5],j=0,a=0; clrscr(); // clear the screen cout<<"Enter the elements of the array"<<endl; for(int i=1;i<=5;i++) { cout<<"Enter number "<<endl; cin>>number[i]; } cout<<"The original list is "; for(i=1;i<=5;i++) { cout<<number[i]<<"\t"; } cout<<endl; cout<<endl<<"Thank You ! The data entry is over"<<endl; cout<<"Press any key to continue"; getch(); cout<<"\a\a"; // sorting of data for(int k=2;k<=5;k++) { a=number[k]; j=k-1; while(a<number[j] && j>0) { number[j+1]=number[j]; j=j-1; } number[j+1]=a; } cout<<endl; cout<<"The list in ascending order is "; cout<<endl; for(i=1;i<=5;i++) cout<<number[i]<<"\t"; cout<<endl<<"Press any key to return to the editor"; getch(); return 0; }

[Link] AM [Link]

// Program to display Fibonacci numbers which are prime. #include<iostream.h> #include<conio.h> #include<stdio.h> // Declaration of the function int isprime(int); main() { clrscr(); int p,a=1,b=2,c=0; p=isprime(a);// calling function if (p==1) cout<<a<<" "; p=isprime(b);// calling function if (p==1) cout<<b<<" "; while(c<=10000) { c=a+b; p=isprime(c); if((p==1) && (c<=10000)) cout<<c<<" "; a=b; b=c; } cout<<endl; cout<<"Press any key to continue"; getch(); return 0; } // Defining the function int isprime(int x) { int i; if (x==1) return 0; else { int pop=1; for(i=2;i<x;i++) { if((x%i==0)) pop=2; } return pop; } }

[Link] AM [Link]

// Adding two angles. #include<iostream.h> #include<conio.h> #include<stdio.h> // Definition of the structure angle struct angle { // two member variables int degrees; int minutes; }; angle sumangle(angle, angle); // function with structure as arguments and returning structures. main() { clrscr(); angle pangle[3]; for(int i=0;i<2;i++) { cout<<"Enter angle in degrees and minutes"; cin>>pangle[i].degrees; cin>>pangle[i].minutes; } // Data entered in two array cells pangle[2]=sumangle(pangle[0],pangle[1]); cout<<"The sum of two angles is "; cout<<endl; cout<<pangle[2].degrees<<"Degrees and "; cout<<pangle[2].minutes<<"Minutes"; cout<<endl; cout<<endl; cout<<"Press any key to continue"; getch(); return 0; } // Defining the function angle sumangle(angle x, angle y) { angle z; [Link]=[Link]+[Link]; [Link]=[Link]+[Link]; if([Link]>=60) { [Link]=[Link]-60; [Link]=[Link]+1; } return z; }

[Link] AM [Link]

// Searching element in an array using binary search #include<iostream.h> #include<conio.h> #include<stdio.h> #include<process.h> main() { clrscr(); int marks[100],x=0,i=0,n=0,middle=0,pos=0,first=0; cout<<"Enter the number of elements required for storage"; cout<<endl; cin>>n; for(i=0;i<n;i++) { cout<<"Enter value "; cin>>marks[i]; } char op='y'; while ((op=='y') || (op=='Y')) { int last = n-1; pos=-1; cout<<"Enter the element to be searched"; cout<<endl; cin>>x; while((pos==-1)&&(first<=last)) { // Application of binary search middle=(first+last)/2; if (marks[middle]==x) { pos=middle; } if(marks[middle]<x) first=middle+1; else last=middle-1; } if (pos==-1) cout<<"Sorry not present in the list"<<endl; else cout<<"The element lies in the array at position"<<pos+1; cout<<endl; cout<<"Enter option y/n"; cin>>op; } getch(); return 0; }

[Link] AM [Link]

// Program to implement Function Overloading #include<iostream.h> #include<conio.h> #include<stdio.h> #include<process.h> // declaration of overloaded functions void rectangle(int,char); void rectangle(int,int,char); main() { clrscr(); rectangle(2,5,'@'); rectangle(1,'a'); rectangle(2,'b'); rectangle(3,'c'); rectangle(4,'d'); cout<<"Press any key to continue"; getch(); return 0; } void rectangle(int n,char ch) { int i,j; for(i=0;i<n;i++) { for(j=0;j<n;j++) { cout<<ch; } cout<<endl; } } void rectangle(int l,int b, char ch) { for(int m=0;m<l;m++) { for(int n=0;n<b;n++) { cout<<ch; } cout<<endl; } }

[Link] AM [Link]

// Program to implement bubble sort for a multi-dimensional array[10][20] // The array is stored through random generation of numbers // between the defined range 1 to 500 #include <iostream.h> #include <iomanip.h> #include <stdlib.h> #include <time.h> #include <process.h> #include <conio.h> #define MAX 500 //Highest possible value that #define MIN 1 //Lowest possible value that #define ORDER < //How you want the list sorted. void main() { clrscr(); int i, j, l, array[10][20]; int row, col, x, y=0, z; int temp, moves=0; srand((unsigned) time(NULL)); x=101; for(row = 0; row < 10; row++) { for(col = 0; col < 20; col++) { x = rand() % MAX + MIN; array[row][col] = x; } } for(row = 0; row < 10; row++) //displays the //unsorted array { for(col = 0; col < 20; col++) { cout<<setw(3)<<array[row][col]<<" "; } cout<<endl; } cout<<"This is the original array"<<endl; cout<<"Enter any key"<<endl; cin>>l;

[Link] AM [Link]

system("cls"); //Clears the screen of the //unsorted array for(i = 0; i < 200; i++) { z=1; for(j = 0; j < 199; j++) { if(array[y][z] ORDER array[y][z - 1]) { temp = array[y][z]; array[y][z] = array[y][z - 1]; array[y][z - 1]=temp; moves++; } z++; } } for(row = 0; row < 10; row++) //displays the //sorted array { for(col = 0; col < 20; col++) { cout<<setw(3)<<array[row][col]<<" "; } cout<<endl; } cout<<moves<<" moves where made to sort this list"<<endl; cout<<"Press any key to continue"<<endl; getch(); }

[Link] AM [Link]

// Program for Data File Manipulation of data entry/storage of employees // Writing Structures in a data file. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<process.h> #include<fstream.h> // Definition of the structure struct employee { int empcode; char name[20]; int hrworked; float rate; }; main() { clrscr(); int n; employee emp[100]; ofstream file1; [Link]("[Link]"); cout<<"Enter number of employees "; cin>>n; for(int i=0;i<n;i++) { cout<<"Enter employee code"; cin>>emp[i].empcode; cout<<endl; cout<<"Enter employee name"; cin>>emp[i].name; cout<<"Enter hours worked"; cin>>emp[i].hrworked; cout<<endl<<"Enter rate"; cin>>emp[i].rate; [Link]((char *) & emp[i],sizeof(employee)); } [Link](); ifstream file2; [Link]("[Link]"); i=1; //[Link](0); while(file2) { [Link]((char*) &emp[i],sizeof(employee)); cout<<"Wage is "<<emp[i].hrworked*emp[i].rate; } [Link](); cout<<"Press any key to continue"; getch(); return 0;

[Link] AM [Link]

[Link] AM [Link]

// Program to accept a number x. // Count number of digits in x and store it in n, form y that // has the number of digits n at ten's place and the most // significant digit of x at one's place. // Display y. sample input: x= 16833, y = 51, // since [Link] digits of x is 5 and 1 is the msd of x. #include<conio.h> #include<iostream.h> main() { clrscr(); int x,y,z,i,n=0,num, msd, digit; cout<<"Enter any number as x"<<endl; cin>>x; // computing number of digits. num=x; while(num>0) { digit=num%10; n=n+1; num=num/10; } msd=digit; y=n*10+msd; cout<<"The value of Y is "<<y; getch(); return 0; }

[Link] AM [Link]

// Program to implement Linked List. #include <iostream.h> #include <conio.h> struct node { node* ptr; int data; }; class list { node* lastptr; public: list(); ~list(); void add(int); void remove(int); void display(); node* searchnode(int); void releasenode(); }; list::list() { lastptr='\0'; } list::~list() { while (lastptr) { node* thisptr=lastptr; lastptr=lastptr->ptr; delete thisptr; } } void list::add(int value) { node* thisptr=new(node); thisptr->data=value; thisptr->ptr=lastptr; lastptr=thisptr; } node* list::searchnode(int value) { node* thisptr=lastptr; while (thisptr) { if (thisptr->data==value)

[Link] AM [Link]

break; thisptr=thisptr->ptr; } return thisptr; } void list::remove(int value) { node* thisptr=searchnode(value); if (!thisptr) return; while (thisptr->ptr) { node* pptr=thisptr->ptr; thisptr->data=pptr->data; thisptr=thisptr->ptr; } releasenode(); } void list::releasenode() { node* thisptr=lastptr; node* previousptr; while (thisptr->ptr) { previousptr=thisptr; thisptr=thisptr->ptr; } if (thisptr==lastptr) lastptr='\0'; else previousptr->ptr='\0'; delete thisptr; } void list::display() { node* thisptr=lastptr; //Loop until this pointer equal to NULL. while (thisptr) { cout<<"Data : "<<thisptr->data<<"\n"; cout<<"Address : "<<thisptr->ptr<<"\n"; thisptr=thisptr->ptr; } } void main() { list linklist; //add number(1 until 7) into link list. [Link](1); [Link](2);
[Link] AM [Link]

[Link](3); [Link](4); [Link](5); [Link](6); [Link](7); getch(); //remove number 4 from the list. [Link](4); //display the number in descending order. [Link](); cout<<endl; cout<<"Press any key to continue"<<endl; getch(); }

[Link] AM [Link]

// Program to combine two arrays and sort them in order in one. #include <stdio.h> #include <conio.h> #define NMAX 10 void printIntArray(int a[], int n); void merge(int c[], int *nc, int a[], int na, int b[], int nb); int main(void) { int x[NMAX] = {1,3,5,6,7}; /* The first sorted sequence */ int y[NMAX] = {2,3,4}; /* The second sorted sequence */ int z[NMAX+NMAX]; /* The merge sequence */ int nz; merge(z,&nz,x,5,y,3); printIntArray(z,nz); getch(); } void printIntArray(int a[], int n) /* n is the number of elements in the array a. * These values are printed out, five per line. */ { int i; for (i=0; i<n; ){ printf("\t%d ", a[i++]); if (i%5==0) printf("\n"); } printf("\n"); } void merge(int c[], int *nc, int a[], int na, int b[], int nb){ int cursora, cursorb, cursorc; cursora=cursorb=cursorc=0; while((cursora<na)&&(cursorb<nb)) if (a[cursora]<=b[cursorb]) c[cursorc++]=a[cursora++]; else c[cursorc++]=b[cursorb++]; while(cursora<na) c[cursorc++]=a[cursora++]; while(cursorb<nb) c[cursorb++]=b[cursorb++]; *nc = cursorc;

[Link] AM [Link]

[Link] AM [Link]

// Lottery Game #include <iostream.h> #include <stdlib.h> #include <string.h> #include <fstream.h> #include <conio.h> int fivemillion_winner() { ofstream fout; char name[50]; char date[9]; [Link]("c:/windows/desktop/Lottery Jackpot [Link]", ios::out | ios::app); cout << "Congratulations. Enter the name you want in the high score book "; cout << "\n\nEnter your Highscore name: "; cin >> name; cout << "\nEnter the date(dd/mm/yy): "; cin >> date; fout << date << " - " << name << endl; cout << "\nThankyou!"; [Link](); return 0; } int main() { clrscr(); srand((unsigned)time(NULL)); int player_num = 1; int p1guess = 0; int p2guess = 0; char over = 'y'; int winner = rand() % 100 +1; cout << cout << cout << cout << cout << cout << cout << cout << "Welcome to the Lottery Game!!!! The game where you can win prizes!!!. " << endl; "Here are the Prizes\n\n"; " 1. $5,000,000 - Number Bang On" << endl; " 2. $2,500,000 - Number One Off" << endl; " 3. $1,000,000 - Number Two Off" << endl; " 4. $500,000 - Number Three Off" << endl; " 5. $250,000 - Number Four Off" << endl << endl; "If you are more that five numbers off you win nothing...\n\n";

while (over != 'n') { tryagain:; cout << "Enter the number of Players(1 or 2): "; cin >> player_num; if (player_num > 2) { cout << "\nI SAID 1 OR 2!! NOT " << player_num << "!!!\n";

[Link] AM [Link]

goto tryagain; } if (player_num == 1) { cout << "\nOne Player it is!!"; cout << "\n\nEnter what you think the number is. Between 1 and 100: "; cin >> p1guess; if (p1guess == winner) { cout << "\nTHATS THE EXACT NUMBER!! YOU WIN $5,000,000!!\n\n"; fivemillion_winner(); } else if ((p1guess == winner + 1) || (p1guess == winner - 1)) cout << "\nYOU WIN $2,500,000. The First Place Winner was: " << winner << "\n\n"; else if ((p1guess == winner + 2) || (p1guess == winner - 2)) cout << "\nYOU WIN $1,000,000. The First Place Winner was: " << winner << "\n\n"; else if ((p1guess == winner + 3) || (p1guess == winner - 3)) cout << "\nYOU WIN $500,000. The First Place Winner was: " << winner << "\n\n"; else if ((p1guess == winner + 4) || (p1guess == winner - 4)) cout << "\nYOU WIN $250,000. The First Place Winner was: " << winner << "\n\n"; else cout << "Sorry. You don't win anything. The Winning Number was: " <<winner << "\n\n"; } if (player_num == 2) { cout << "\nTwo Player it is!!"; cout << "\n\nPlayer 1: Enter what you think the number is. Between 1 and 100: "; cin >> p1guess; cout << "\n\nPlayer 2: Enter what you think the number is. Between 1 and 100: "; cin >> p2guess; if (p1guess == winner) { cout << "\nTHATS THE EXACT NUMBER PLAYER 1!! YOU WIN $5,000,000!!\n"; fivemillion_winner(); } else if ((p1guess == winner + 1) || (p1guess == winner - 1)) cout << "\nYOU WIN $2,500,000 PLAYER 1. The First Place Winner was: " << winner << "\n\n"; else if ((p1guess == winner + 2) || (p1guess == winner - 2)) cout << "\nYOU WIN $1,000,000 PLAYER 1. The First Place Winner was: " << winner << "\n\n"; else if ((p1guess == winner + 3) || (p1guess == winner - 3)) cout << "\nYOU WIN $500,000 PLAYER 1. The First Place Winner was: " << winner << "\n\n"; else if ((p1guess == winner + 4) || (p1guess == winner - 4)) cout << "\nYOU WIN $250,000 PLAYER 1. The First Place Winner was: " << winner << "\n\n"; else cout << "Sorry. You don't win anything player 1. The Winning Number was: " <<winner << "\n\n"; if (p2guess == winner) { cout << "\nTHATS THE EXACT NUMBER PLAYER 2!! YOU WIN $5,000,000!!\n"; fivemillion_winner(); } else if ((p2guess == winner + 1) || (p2guess == winner - 1)) cout << "\nYOU WIN $2,500,000 PLAYER 2. The First Place Winner was: " << winner << "\n\n"; else if ((p2guess == winner + 2) || (p2guess == winner - 2)) cout << "\nYOU WIN $1,000,000 PLAYER 2. The First Place Winner was: " << winner << "\n\n"; else if ((p2guess == winner + 3) || (p2guess == winner - 3))
[Link] AM [Link]

cout << "\nYOU WIN $500,000 PLAYER 2. The First Place Winner was: " << winner << "\n\n"; else if ((p2guess == winner + 4) || (p2guess == winner - 4)) cout << "\nYOU WIN $250,000 PLAYER 2. The First Place Winner was: " << winner << "\n\n"; else cout << "Sorry. You don't win anything player 2. The Winning Number was: " <<winner << "\n\n"; } cout << "Would you like to try again(y/n)?? "; cin >> over; system("cls"); } getch(); return 0; }

[Link] AM [Link]

// Program to depict the process of linear search #include<iostream.h> #include<process.h> #include<conio.h> main() { clrscr(); int num[10],m; cout<<"Enter any ten numbers as elements of an array"<<endl; for (int i=0;i<10;i++) { cin>>num[i]; } cout<<endl<<"Enter any number "; cin>>m; cout<<endl; for (int j=0;j<10;j++) { if (num[j] == m) {cout<<m<<" is present in the array"<<endl; getch(); exit(0);} } getch(); return 0; }

[Link] AM [Link]

// Program to return the inverse of any entered number. # include <iostream.h> #include<conio.h> int function(int g); int main() { int n, exit; cout <<"this program will give the inverse of any number:"<<"\t"; cin>>n; function(n); cout<<"\n"<<"print exit to quit this program:"<<"\t"; getch(); return 0; } int function(int g) { int p=1, f, i; while (p!=0) { p=g/10; f=p*10; i=g-f; g=p; cout<<i; } return i; }

[Link] AM [Link]

// Program to input a number and check if it is a Magic Number #include<iostream.h> #include<conio.h> main() { clrscr(); int num,num1,i,j,k,flag=0,n,sum=0,c=0; cout<<"enter any no."; cin>>num; num1=num; while(flag==0) { while(num!=0) { n=num%10; sum=sum+n; num=num/10; c=c+1; } if (c==1) { if (sum==1) cout<<num1<<" is a magic number"; else cout<<num1<<" is not a magic number"; flag=1;} num=sum; sum=0; c=0; } getch(); }

[Link] AM [Link]

//This program creates a magic square box of order n x n. // The speciality of a magic square box is that the // sum of elements of any row or any column is always equal. #include <stdio.h> #include <conio.h> #include <math.h> #include <stdlib.h> #include <alloc.h> int arr[10][10], n, a,b,i; void magic(int , int , int, int); void main() { int j,x,k; clrscr(); printf("\n Enter size of matrix (n X n, where n is odd):"); scanf("%d", &n); printf("\n Enter 1st element of the %d sequential elements:",n*n); scanf("%d", &x); for (i=0; i<n; i++) { for (k=0; k<n; k++) { arr[i][k]=-1; } } arr[0][n/2]=x; magic(0,n/2, x, n); printf("\n"); for (i=0; i<n; i++) { for (k=0; k<n; k++) { printf(" %3d ", arr[i][k]); } printf("\n"); } getch(); } void magic( int a, int b, int x, int n) { int c; c=1; for (x=x+1,i=2; i<=n*n; i++,c++,x++) { if(c<n) { a=a-1; b=b-1;

[Link] AM [Link]

if (a==-1) a=n-1; if (b==-1) b=n-1; } else { a=a+1; c=0; } arr[a][b]=x; } }

[Link] AM [Link]

// Program to insert comma at appropriate position in an entered (max-15) // digit number as per the mathematical theory. #include <iostream.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> void AddCommas( char * In, char * Out ); int main() { clrscr(); char Input[17]; char Output[21]; printf("Please enter a number (max 15 char) "); [Link](Input,16); AddCommas(Input, Output); cout<<Output<<endl; system("pause"); getch(); return 0; } void AddCommas( char * In, char * Out ) { int nLength = strlen(In); int incr; int nCount; int nPosition = 0; if( (nLength % 3) == 0 ) nCount = 0; else { if( ((nLength % 3) == 1) && (In[0] == '-') ) nCount = -1; else nCount = 3 - (nLength % 3); } for ( incr = 0; incr < nLength; incr++) { if( nCount == 3 ) { Out[nPosition] = ','; nPosition++;

[Link] AM [Link]

nCount = 0; } Out[nPosition] = In[incr]; nPosition++; nCount++; } Out[nPosition] = 0; //terminating zero }

[Link] AM [Link]

// Program to display Consonants and Vowels output from an entered string #include <iostream.h> #include <string.h> #include <conio.h> void main() { clrscr(); int consonant =0; int vowel =0; int k =0; char response[20]; cout<<"Please enter a word "<<endl; cin>>response; while (k<20 && response[k] != '\0') { switch(response [k]) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': ++vowel; break; default: ++consonant; break; } ++k; } cout<<"There are "<<vowel<<" vowel(s) in your string"<<endl; cout<<"There are "<<consonant<<" consonant(s)in your string"<<endl; cout<<"Press any key to continue"<<endl; getch(); }

[Link] AM [Link]

// Program to perform: Matricies-add,subtract & more. #include<iostream.h> #include<conio.h> #include<string.h> #include<iomanip.h> void menu(); void determan(); void multi(); void add(); void subtract(); void exit(); void suberror1(); void suberror2(); void adderror1(); void adderror2(); void multierror2(); void multierror1(); void equation(); void equationerror1(); void equationerror2();

int main() { cout<<"\n\n\n\n\n"; cout<<setw(40)<<"*************\n"; cout<<setw(40)<<"| MATRACIES |\n"; cout<<setw(40)<<"*************\n"; cout<<setw(41)<<"*************\n\n"; cout<<setw(48)<<"Press any key to continue..."; getch(); clrscr(); menu(); return 0; } void menu() { int todo; //This is the main menu.

cout<<setw(20)<<"Main Menu\n\n"; cout<<"1-Find the dertermanants of a 3*3\n"; cout<<"2-Multiply two 3*3\n"; cout<<"3-Add two 3*3\n"; cout<<"4-Subtract two 3*3\n"; cout<<"5-Solve an equation with 3 variables\n"; cout<<"6-Exit Program\n\n"; cout<<"What do you want to do Today?-";

[Link] AM [Link]

cin>>todo; clrscr(); if (todo==1) determan(); if (todo==2) multi(); if (todo==3) add(); if (todo==4) subtract(); if (todo==5) equation(); if (todo==7) exit(); } void determan() //This Figures out Determanants { int back,back2; double a1,a2,a3,b1,b2,b3,c1,c2,c3,determ; cout<<setw(20)<<"| a1 b1 c1 |\n"; cout<<setw(20)<<"| a2 b2 c2 |\n"; cout<<setw(21)<<"| a3 b3 c3 |\n\n"; cout<<"Enter a1-"; cin>>a1; cout<<endl; cout<<"Enter a2-"; cin>>a2; cout<<endl; cout<<"Enter a3-"; cin>>a3; cout<<endl; cout<<"Enter b1-"; cin>>b1; cout<<endl; cout<<"Enter b2-"; cin>>b2; cout<<endl; cout<<"Enter b3-"; cin>>b3; cout<<endl; cout<<"Enter c1-"; cin>>c1; cout<<endl; cout<<"Enter c2-"; cin>>c2; cout<<endl; cout<<"Enter c3-"; cin>>c3; cout<<endl; clrscr(); determ=(a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)-(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2); if (determ==0)
[Link] AM [Link]

cout<<"Impossible to solve, the Determanant of a matrix cannot equal 0"<<endl; cout<<" | "<<a1<<" "<<b1<<" "<<c1<<" |\n"; cout<<"The Determanant of | "<<a2<<" "<<b2<<" "<<c2<<" |="<<determ<<endl; cout<<" | "<<a3<<" "<<b3<<" "<<c3<<" |\n"; cout<<endl; cout<<"Go Back to Main Menu Press 1 Go back to Determanants press 2-"; cin>>back; clrscr(); if (back==1) menu(); if (back==2) determan(); if (back>2) cout<<"Error Please only press 1 or 2."<<endl; cout<<endl; cout<<"Go Back to Main Menu Press 1 Go back to Determanants press 2-"; cin>>back; clrscr(); if (back2==1) menu(); if (back2==2) determan(); if (back2>2) cout<<"Error"; } void multi() //This Multiplies two matriceis { int a,b; double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,w1,w2,w3,w4,w5,w6,w7,w8,w9; cout<<setw(40)<<"| a1 b1 c1 | | d1 e1 f1 |"<<endl; cout<<setw(40)<<"| a2 b2 c2 | * | d2 e2 f2 |"<<endl; cout<<setw(40)<<"| a3 b3 c3 | | d3 e3 f3 |"<<endl; cout<<endl; cout<<"Enter Value for a1- "; cin>>a1; cout<<"Enter Value for a2- "; cin>>a2; cout<<"Enter Value for a3- "; cin>>a3; cout<<"Enter Value for b1- "; cin>>b1; cout<<"Enter Value for b2- "; cin>>b2; cout<<"Enter Value for b3- "; cin>>b3; cout<<"Enter Value for c1- "; cin>>c1; cout<<"Enter Value for c2- "; cin>>c2; cout<<"Enter Value for c3- "; cin>>c3; cout<<"Enter Value for d1- "; cin>>d1;
[Link] AM [Link]

cout<<"Enter Value for d2- "; cin>>d2; cout<<"Enter Value for d3- "; cin>>d3; cout<<"Enter Value for e1- "; cin>>e1; cout<<"Enter Value for e2- "; cin>>e2; cout<<"Enter Value for e3- "; cin>>e3; cout<<"Enter Value for f1- "; cin>>f1; cout<<"Enter Value for f2- "; cin>>f2; cout<<"Enter Value for f3- "; cin>>f3; w1=(a1*d1)+(b1*d2)+(c1*d3); w2=(a2*d1)+(b2*d2)+(c2*d3); w3=(a3*d1)+(b3*d2)+(c3*d3); w4=(a1*e1)+(b1*e2)+(c1*e3); w5=(a2*e1)+(b2*e2)+(c2*e3); w6=(a3*e1)+(b3*e2)+(c3*e3); w7=(a1*f1)+(b1*f2)+(c1*f3); w8=(a2*f1)+(b2*f2)+(c2*f3); w9=(a3*f1)+(b3*f2)+(c3*f3); clrscr(); cout<<"| "<<a1<<" "<<b1<<" "<<c1<<" | | "<<d1<<" "<<e1<<" "<<f1<<" | | "<<w1<<" "<<w4<<" "<<w7<<" |"<<endl; cout<<"| "<<a2<<" "<<b2<<" "<<c2<<" | * | "<<d2<<" "<<e2<<" "<<f2<<" |= | "<<w2<<" "<<w5<<" "<<w8<<" |"<<endl; cout<<"| "<<a3<<" "<<b3<<" "<<c3<<" | | "<<d3<<" "<<e3<<" "<<f3<<" | | "<<w3<<" "<<w6<<" "<<w9<<" |"<<endl; cout<<endl; cout<<"Go back to Multiplication press 1 go back to Main Menu press 2- "; cin>>a; clrscr(); if (a==1) multi(); if (a==2) menu(); if (a>2) multierror1(); } void add() //This adds two matriceis { int a,b; double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,w1,w2,w3,w4,w5,w6,w7,w8,w9; cout<<setw(40)<<"| a1 b1 c1 | | d1 e1 f1 |"<<endl; cout<<setw(40)<<"| a2 b2 c2 | + | d2 e2 f2 |"<<endl; cout<<setw(40)<<"| a3 b3 c3 | | d3 e3 f3 |"<<endl; cout<<endl; cout<<"Enter Value for a1- "; cin>>a1;
[Link] AM [Link]

cout<<"Enter Value for a2- "; cin>>a2; cout<<"Enter Value for a3- "; cin>>a3; cout<<"Enter Value for b1- "; cin>>b1; cout<<"Enter Value for b2- "; cin>>b2; cout<<"Enter Value for b3- "; cin>>b3; cout<<"Enter Value for c1- "; cin>>c1; cout<<"Enter Value for c2- "; cin>>c2; cout<<"Enter Value for c3- "; cin>>c3; cout<<"Enter Value for d1- "; cin>>d1; cout<<"Enter Value for d2- "; cin>>d2; cout<<"Enter Value for d3- "; cin>>d3; cout<<"Enter Value for e1- "; cin>>e1; cout<<"Enter Value for e2- "; cin>>e2; cout<<"Enter Value for e3- "; cin>>e3; cout<<"Enter Value for f1- "; cin>>f1; cout<<"Enter Value for f2- "; cin>>f2; cout<<"Enter Value for f3- "; cin>>f3; clrscr(); w1=a1+d1; w2=a2+d2; w3=a3+d3; w4=b1+e1; w5=b2+e2; w6=b3+e3; w7=c1+f1; w8=c2+f2; w9=c3+f3; clrscr(); cout<<"| "<<a1<<" "<<b1<<" "<<c1<<" | | "<<d1<<" "<<e1<<" "<<f1<<" | | "<<w1<<" "<<w4<<" "<<w7<<" |"<<endl; cout<<"| "<<a2<<" "<<b2<<" "<<c2<<" | + | "<<d2<<" "<<e2<<" "<<f2<<" |= | "<<w2<<" "<<w5<<" "<<w8<<" |"<<endl; cout<<"| "<<a3<<" "<<b3<<" "<<c3<<" | | "<<d3<<" "<<e3<<" "<<f3<<" | | "<<w3<<" "<<w6<<" "<<w9<<" |"<<endl; cout<<endl; cout<<"Go back to Addition press 1 go back to Main Menu press 2- "; cin>>a;
[Link] AM [Link]

clrscr(); if (a==1) add(); if (a==2) menu(); if (a>2) adderror1(); } void subtract() //This Subtracts two matriceis { int a; double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,w1,w2,w3,w4,w5,w6,w7,w8,w9; cout<<setw(40)<<"| a1 b1 c1 | | d1 e1 f1 |"<<endl; cout<<setw(40)<<"| a2 b2 c2 | - | d2 e2 f2 |"<<endl; cout<<setw(40)<<"| a3 b3 c3 | | d3 e3 f3 |"<<endl; cout<<endl; cout<<"Enter Value for a1- "; cin>>a1; cout<<"Enter Value for a2- "; cin>>a2; cout<<"Enter Value for a3- "; cin>>a3; cout<<"Enter Value for b1- "; cin>>b1; cout<<"Enter Value for b2- "; cin>>b2; cout<<"Enter Value for b3- "; cin>>b3; cout<<"Enter Value for c1- "; cin>>c1; cout<<"Enter Value for c2- "; cin>>c2; cout<<"Enter Value for c3- "; cin>>c3; cout<<"Enter Value for d1- "; cin>>d1; cout<<"Enter Value for d2- "; cin>>d2; cout<<"Enter Value for d3- "; cin>>d3; cout<<"Enter Value for e1- "; cin>>e1; cout<<"Enter Value for e2- "; cin>>e2; cout<<"Enter Value for e3- "; cin>>e3; cout<<"Enter Value for f1- "; cin>>f1; cout<<"Enter Value for f2- "; cin>>f2; cout<<"Enter Value for f3- "; cin>>f3; clrscr(); w1=a1-d1;
[Link] AM [Link]

w2=a2-d2; w3=a3-d3; w4=b1-e1; w5=b2-e2; w6=b3-e3; w7=c1-f1; w8=c2-f2; w9=c3-f3; clrscr(); cout<<"| "<<a1<<" "<<b1<<" "<<c1<<" | | "<<d1<<" "<<e1<<" "<<f1<<" | | "<<w1<<" "<<w4<<" "<<w7<<" |"<<endl; cout<<"| "<<a2<<" "<<b2<<" "<<c2<<" | - | "<<d2<<" "<<e2<<" "<<f2<<" |= | "<<w2<<" "<<w5<<" "<<w8<<" |"<<endl; cout<<"| "<<a3<<" "<<b3<<" "<<c3<<" | | "<<d3<<" "<<e3<<" "<<f3<<" | | "<<w3<<" "<<w6<<" "<<w9<<" |"<<endl; cout<<endl; cout<<"Go back to Subtraction press 1 go back to Main Menu press 2- "; cin>>a; clrscr(); if (a==1) subtract(); if (a==2) menu(); if (a<2) suberror1(); if (a=='a') suberror1(); } void exit() //This exits the program { char *yes; cout<<"Thank you for usin my Matrix program. "<<endl; cout<<endl; cout<<"Are you sure you want to quit?(y/n)- "; cin>>yes; clrscr(); if (yes=="n") menu(); } void suberror1() { int c; cout<<"Error Please only press 1 or 2."<<endl; cout<<endl; cout<<"Go back to Subtraction press 1 go back to Main Menu press 2- "; cin>>c; clrscr(); if (c==1) subtract(); if(c==2) menu(); if (c>2) suberror2(); }
[Link] AM [Link]

void suberror2() { int d; cout<<"Error Please only press 1 or 2."<<endl; cout<<endl; cout<<"Go back to Subtraction press 1 go back to Main Menu press 2- "; cin>>d; clrscr(); if (d==1) subtract(); if(d==2) menu(); if (d>2) suberror1(); } void adderror1() { int c; cout<<"Error Please only press 1 or 2."<<endl; cout<<endl; cout<<"Go back to Addition press 1 go back to Main Menu press 2- "; cin>>c; clrscr(); if (c==1) add(); if(c==2) menu(); if (c>2) adderror2(); } void adderror2() { int d; cout<<"Error Please only press 1 or 2.\n"; cout<<endl; cout<<"Go back to Addition press 1 go back to Main Menu press 2- "; cin>>d; clrscr(); if (d==1) add(); if(d==2) menu(); if (d>2) adderror1(); } void multierror1() { int c; cout<<"Error Please only press 1 or 2.\n"; cout<<endl; cout<<"Go back to Multiplication press 1 go back to Main Menu press 2- "; cin>>c; clrscr(); if (c==1)
[Link] AM [Link]

multi(); if(c==2) menu(); if (c>2) multierror2(); } void multierror2() { int d; cout<<"Error Please only press 1 or 2.\n"; cout<<endl; cout<<"Go back to Multiplication press 1 go back to Main Menu press 2- "; cin>>d; clrscr(); if (d==1) multi(); if(d==2) menu(); if (d>2) multierror1(); } void equation() { double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,x,y,z,m; cout<<setw(30)<<"A1x+B1y+C1z=D1"<<endl; cout<<setw(30)<<"A2x+B2y+C2z=D2"<<endl; cout<<setw(30)<<"A3x+B3y+C3z=D3"<<endl; cout<<endl; cout<<"Enter the value for A1-"; cin>>a1; cout<<"Enter the value for A2-"; cin>>a2; cout<<"Enter the value for A3-"; cin>>a3; cout<<"Enter the value for B1-"; cin>>b1; cout<<"Enter the value for B2-"; cin>>b2; cout<<"Enter the value for B3-"; cin>>b3; cout<<"Enter the value for C1-"; cin>>c1; cout<<"Enter the value for C2-"; cin>>c2; cout<<"Enter the value for C3-"; cin>>c3; cout<<"Enter the value for D1-"; cin>>d1; cout<<"Enter the value for D2-"; cin>>d2; cout<<"Enter the value for D3-"; cin>>d3;
[Link] AM [Link]

clrscr(); x=((d1*b2*c3)+(d2*b3*c1)+(d3*b1*c2)-(c1*b2*d3)-(c2*b3*d1)-(c3*b1*d2))/((a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2)); y=((a1*d2*c3)+(a2*d3*c1)+(a3*d1*c2)-(c1*d2*a3)-(c2*d3*a1)-(c3*d1*a2))/((a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2)); z=((a1*b2*d3)+(a2*b3*d1)+(a3*b1*d2)-(d1*b2*a3)-(d2*b3*a1)-(d3*b1*a2))/((a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2)); cout<<"In the Equations:\n"; cout<<a1<<"x+"<<b1<<"y+"<<c1<<"z="<<d1<<endl; cout<<a2<<"x+"<<b2<<"y+"<<c2<<"z="<<d2<<endl; cout<<a3<<"x+"<<b3<<"y+"<<c3<<"z="<<d3; cout<<"\n\n"; cout<<"X="<<x<<", Y="<<y<<", Z="<<z; cout<<"\n\n"; cout<<"If you want to solve more equations press 1, if you want to go back\n"; cout<<" to the Main Menu press 2-"; cin>>m; clrscr(); if (m==1) equation(); if (m==2) menu(); if (m>2) equationerror1(); } void equationerror1() { int c; cout<<"Error Please only press 1 or 2.\n"; cout<<endl; cout<<"If you want to solve more equations press 1, if you want to go back\n"; cout<<" to the Main Menu press 2-"; cin>>c; clrscr(); if (c==1) equation(); if(c==2) menu(); if (c>2) equationerror2(); } void equationerror2() { int d; cout<<"Error Please only press 1 or 2.\n"; cout<<endl; cout<<"If you want to solve more equations press 1, if you want to go back\n"; cout<<" to the Main Menu press 2-"; cin>>d; clrscr(); if (d==1) equation(); if(d==2) menu();
[Link] AM [Link]

if (d>2) equationerror1(); }

[Link] AM [Link]

// Program for reading, writing and multiplication of the matrices. #include <iostream.h> #include <iomanip.h> #include <conio.h> const int rows = 3; // number of rows in matrix (must be constant) const int columns = 3; // number of columns in matrix (must be constant) void ReadMatrix (float ma[rows][columns]) // this function reads matrix from keyboard { int r, c; cout << "\nPlease enter matrix"; for (r=0; r<rows; r++) { for (c=0; c<columns; c++) { cout << "\nElement A(" << (r+1) << "," << (c+1) << ") "; cin >> ma[r][c]; } } } void WriteMatrix (float ma[rows][columns]) // this function writes matrix on screen { int r, c; cout << "\nMatrix is:"; for (r=0; r<rows; r++) { cout << "\n"; for (c=0; c<columns; c++) { // setw(10) adds space to make all numbers 10 characters wide cout << setw(10) << ma[r][c] << " "; } } } void MultiplyByScalar (float sq[rows][columns], float fac) // this function multiplies a matrix by a scalar { int i, j; for (i=0; i<rows; i++) { for (j=0; j<columns; j++) { sq[i][j] = sq[i][j] * fac; } } } void main () {

[Link] AM [Link]

// declare matrix and scalar float A[rows][columns], f; // get matrix from user ReadMatrix(A); // get scalar from user cout << "\n\nEnter factor "; cin >> f; // multiply matrix by scalar MultiplyByScalar (A, f); // output result matrix on screen WriteMatrix(A); // wait for user to press a key getch(); }

[Link] AM [Link]

// Program to perform MergeSort #include #include #include #include <stdlib.h> <conio.h> <stdio.h> <iostream.h>

#define uint32 unsigned int typedef int (*CMPFUN)(int, int);

#define INSERTION_SORT_BOUND 8 /* boundary point to use insertion sort */ void ArraySort(int This[], CMPFUN fun_ptr, uint32 the_len) { uint32 span; uint32 lb; uint32 ub; uint32 indx; uint32 indx2; if (the_len <= 1) return; span = INSERTION_SORT_BOUND; /* insertion sort the first pass */ { int prev_val; int cur_val; int temp_val; for (lb = 0; lb < the_len; lb += span) { if ((ub = lb + span) > the_len) ub = the_len; prev_val = This[lb]; for (indx = lb + 1; indx < ub; ++indx) { cur_val = This[indx]; if ((*fun_ptr)(prev_val, cur_val) > 0) { /* out of order: array[indx-1] > array[indx] */ This[indx] = prev_val; /* move up the larger item first */ /* find the insertion point for the smaller item */ for (indx2 = indx - 1; indx2 > lb;) {

[Link] AM [Link]

temp_val = This[indx2 - 1]; if ((*fun_ptr)(temp_val, cur_val) > 0) { This[indx2--] = temp_val; /* still out of order, move up 1 slot to make room */ } else break; } This[indx2] = cur_val; /* insert the smaller item right here */ } else { /* in order, advance to next element */ prev_val = cur_val; } } } } /* second pass merge sort */ { uint32 median; int* aux; aux = (int*) malloc(sizeof(int) * the_len / 2); while (span < the_len) { /* median is the start of second file */ for (median = span; median < the_len;) { indx2 = median - 1; if ((*fun_ptr)(This[indx2], This[median]) > 0) { /* the two files are not yet sorted */ if ((ub = median + span) > the_len) { ub = the_len; } /* skip over the already sorted largest elements */ while ((*fun_ptr)(This[--ub], This[indx2]) >= 0) { } /* copy second file into buffer */ for (indx = 0; indx2 < ub; ++indx) { *(aux + indx) = This[++indx2]; } --indx; indx2 = median - 1; lb = median - span;
[Link] AM [Link]

/* merge two files into one */ for (;;) { if ((*fun_ptr)(*(aux + indx), This[indx2]) >= 0) { This[ub--] = *(aux + indx); if (indx > 0) --indx; else { /* second file exhausted */ for (;;) { This[ub--] = This[indx2]; if (indx2 > lb) --indx2; else goto mydone; /* done */ } } } else { This[ub--] = This[indx2]; if (indx2 > lb) --indx2; else { /* first file exhausted */ for (;;) { This[ub--] = *(aux + indx); if (indx > 0) --indx; else goto mydone; /* done */ } } } } } mydone: median += span + span; } span += span; } free(aux); } } #define ARRAY_SIZE 2500 int my_array[ARRAY_SIZE]; uint32 fill_array() { int indx; uint32 sum = 0;

[Link] AM [Link]

for (indx=0; indx < ARRAY_SIZE; ++indx) { sum += my_array[indx] = rand(); } return sum; } int cmpfun(int a, int b) { if (a > b) return 1; else if (a < b) return -1; else return 0; } int main() { clrscr(); int indx; uint32 checksum, checksum2; checksum = fill_array(); ArraySort(my_array, cmpfun, ARRAY_SIZE); checksum2 = my_array[0]; for (indx=1; indx < ARRAY_SIZE; ++indx) { checksum2 += my_array[indx]; if (my_array[indx - 1] > my_array[indx]) { printf("bad sort\n"); return(1); } } if (checksum != checksum2) { printf("bad checksum %d %d\n", checksum, checksum2); return(1); } cout<<endl; getch(); return(0); }

[Link] AM [Link]

// Program in C++ to create a 3 by 3 array and // extract the maximum and the maximum alongwith // the original matrix. #include<iostream.h> #include<conio.h> main() { int i,j,a[3][3],max,min; //Creation of matrix A[3][3] cout<<"Enter elements of array A"<<endl; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>a[i][j]; } } max = a[0][0]; min = a[0][0]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { if (a[i][j]>max) max = a[i][j]; if (a[i][j]<min) min = a[i][j]; } } //printing of the original matrix for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<a[i][j]<<" "; } cout<<endl; } cout<<endl; cout<<"The maximum element is "<<max; cout<<endl<<"The minimum element is "<<min; getch(); return 0; }

[Link] AM [Link]

// Program to convert any numeric entry into Words. #include #include #include #include #include <conio.h> <stdio.h> <stdlib.h> <string.h> <iostream.h>

char * itoenglish(long n, int st); void doit(long n, int st); /*GETS THE NUMBER THAT IS TO BE CHANGED TO NUMBERS*/ void main() { long num = 0; clrscr(); while( num >= 0 ) { cout<<"Enter any number ( a negative number to quit )"<<endl; cin>>num; doit( num, 0 ); }; } /*TURNS THE DIGIT TO WORDS AND ADDS THE VALUE TO IT SUCH AS HUNDRED, THOUSAND*/ void doit(long n, int st) { long z, showed; char str[100], out[100]; if (n != 0) { strcpy(out, ""); showed = 0; if ((n / 1000) != 0) { z = n / 1000; n = n - z * 1000; sprintf(str, "%s thousand ", itoenglish(z, 0)); strcat(out, str); showed = 1000; } if ((n / 100) != 0) { z = n / 100;

[Link] AM [Link]

n = n - z * 100; sprintf(str, "%s hundred ", itoenglish(z, 0)); strcat(out, str); showed = 100; } if (n != 0) { z = n; if (showed == 100) strcat(out, "and"); sprintf(str, "%s", itoenglish(z, st)); strcat(out, str); showed = 10; } printf("%s", out); } else if ( n == 0 ) printf("zero"); printf("\n"); } /*CHANGES THE DIGITS TO WORDS*/ char * itoenglish(long n, int st) { char str[100]; char th[2][3]; strcpy(th[0], ""); strcpy(th[1], "TH"); if (n == 0) strcpy(str, th[st]); else if (n == 1) { if (st == 0) strcpy(str, " one"); } else if (n == 2) { if (st == 0) strcpy(str, " two"); } else if (n == 3) { if (st == 0) strcpy(str, " three");
[Link] AM [Link]

} else if (n == 4) sprintf(str, " four%s", th[st]); else if (n == 5) { if (st == 0) strcpy(str, " five"); } else if (n == 6) sprintf(str, " six%s", th[st]); else if (n == 7) sprintf(str, " seven%s", th[st]); else if (n == 8) sprintf(str, " eight%s", th[st]); else if (n == 9) sprintf(str, " nine%s", th[st]); else if (n == 10) sprintf(str, " ten%s", th[st]); else if (n == 11) sprintf(str, " eleven%s", th[st]); else if (n == 12) sprintf(str, " twelve%s", th[st]); else if (n == 13) sprintf(str, " thirteen%s", th[st]); else if (n == 14) sprintf(str, " fourteen%s", th[st]); else if (n == 15) sprintf(str, " fifteen%s", th[st]); else if (n >= 16 && n <= 17) sprintf(str, " %steen%s", itoenglish(n - 10, 0), th[st]); else if (n == 18) sprintf(str, " eighteen%s", th[st]); else if (n == 19) sprintf(str, " nineteen%s", th[st]); else if (n >= 20 && n <= 29) sprintf(str, " twenty%s", itoenglish(n - 20, st)); else if (n >= 30 && n <= 39)
[Link] AM [Link]

sprintf(str, " thirty%s", itoenglish(n - 30, st)); else if (n >= 40 && n <= 49) sprintf(str, " fourty%s", itoenglish(n - 40, st)); else if (n >= 50 && n <= 59) sprintf(str, " fifty%s", itoenglish(n - 50, st)); else if (n >= 60 && n <= 79) sprintf(str, " %sty%s", itoenglish(n / 10, 0), itoenglish(n - (n / 10) * 10, st)); else if (n >= 80 && n <= 89) sprintf(str, " eighty%s", itoenglish(n - 80, st)); else if (n >= 90 && n <= 99) sprintf(str, " %sty%s", itoenglish(n / 10, 0), itoenglish(n - (n / 10) * 10, st)); else strcpy(str, ""); if (strstr(str, "tTH") != NULL) strcpy(strstr(str, "tTH"), "TH"); return(strdup(str)); }

[Link] AM [Link]

// Program to perform Magic Courtesy : ENRICO X //THE MAGICIAN : Enrico Lorenzo // Source: Internet #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> main() { clrscr(); _setcursortype(_NOCURSOR); int x, x2=6, lo, di; int x3=5, x4=3, x5=4; char cho, col, col2, col3; randomize(); clrscr(); sleep(2); textcolor(15); gotoxy(44,13);cprintf("X"); delay(100); textcolor(0); gotoxy(44,13);cprintf(" "); textcolor(15); gotoxy(42,13);cprintf("O"); delay(100); textcolor(0); gotoxy(42,13);cprintf(" "); textcolor(15); gotoxy(41,13);cprintf("C"); delay(100); textcolor(0); gotoxy(41,13);cprintf(" "); textcolor(15); gotoxy(40,13);cprintf("I"); delay(100); textcolor(0); gotoxy(40,13);cprintf(" "); textcolor(15); gotoxy(39,13);cprintf("R"); delay(100); textcolor(0); gotoxy(39,13);cprintf(" "); textcolor(15); gotoxy(38,13);cprintf("N"); delay(100); textcolor(0); gotoxy(38,13);cprintf(" "); textcolor(15); gotoxy(37,13);cprintf("E"); delay(100); textcolor(0); gotoxy(37,13);cprintf(" "); delay(100);

[Link] AM [Link]

textcolor(15); gotoxy(37,13);cprintf("E"); delay(100); textcolor(8); gotoxy(37,13);cprintf("E"); textcolor(15); gotoxy(38,13);cprintf("N"); delay(100); textcolor(8); gotoxy(38,13);cprintf("N"); textcolor(15); gotoxy(39,13);cprintf("R"); delay(100); textcolor(8); gotoxy(39,13);cprintf("R"); textcolor(15); gotoxy(40,13);cprintf("I"); delay(100); textcolor(8); gotoxy(40,13);cprintf("I"); textcolor(15); gotoxy(41,13);cprintf("C"); delay(100); textcolor(8); gotoxy(41,13);cprintf("C"); textcolor(15); gotoxy(42,13);cprintf("O"); delay(100); textcolor(8); gotoxy(42,13);cprintf("O"); textcolor(15); gotoxy(44,13);cprintf("X"); delay(100); textcolor(8); gotoxy(44,13);cprintf("X"); sleep(2); clrscr(); textcolor(15); gotoxy(35,13);cprintf("T"); delay(100); gotoxy(36,13);cprintf("H"); textcolor(8); gotoxy(35,13);cprintf("T"); delay(100); gotoxy(36,13);cprintf("H"); textcolor(15); gotoxy(37,13);cprintf("E"); delay(100); gotoxy(39,13);cprintf("M"); textcolor(8); gotoxy(37,13);cprintf("E"); delay(100); gotoxy(39,13);cprintf("M"); textcolor(15);
[Link] AM [Link]

gotoxy(40,13);cprintf("%c", delay(100); gotoxy(41,13);cprintf("G"); textcolor(8); gotoxy(40,13);cprintf("%c", delay(100); gotoxy(41,13);cprintf("G"); textcolor(15); gotoxy(42,13);cprintf("I"); delay(100); gotoxy(43,13);cprintf("C"); textcolor(8); gotoxy(42,13);cprintf("I"); delay(100); gotoxy(43,13);cprintf("C"); textcolor(15); gotoxy(44,13);cprintf("I"); delay(100); gotoxy(45,13);cprintf("%c", textcolor(8); gotoxy(44,13);cprintf("I"); delay(100); gotoxy(45,13);cprintf("%c", textcolor(15); gotoxy(46,13);cprintf("N"); delay(100); textcolor(8); gotoxy(46,13);cprintf("N"); delay(100); gotoxy(35,13);cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); gotoxy(39,13);cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); delay(100); cprintf(" "); sleep(2); clrscr();

x2);

x2);

x3);

x3);

[Link] AM [Link]

for(x=1; x<=50; x++) { textcolor(8); gotoxy(random(80), random(25));cprintf("%c", x2); delay(10); gotoxy(random(80), random(25));cprintf("%c", x3); delay(10); textcolor(4); gotoxy(random(80), random(25));cprintf("%c", x4); delay(10); gotoxy(random(80), random(25));cprintf("%c", x5); delay(10); } intro: clrscr(); textcolor(8); gotoxy(1,1);cprintf(" nter"); gotoxy(73,25);cprintf(" redits"); gotoxy(68,1);cprintf("THE M%cGICI%cN", x2, x3); gotoxy(1,25);cprintf("Best viewed in maximize window"); textcolor(15); gotoxy(1,1);cprintf("E"); gotoxy(73,25);cprintf("C"); cho=getch(); if(cho=='e' || cho=='E') { clrscr(); for(lo=28; lo<=53; lo++) { textcolor(8); gotoxy(lo,14);cprintf(""); } for(lo=0, di=28; lo<=100; lo+=4, di++) { textcolor(15); gotoxy(28,12);cprintf("initializing trick..."); gotoxy(28,13);cprintf("%d%", lo); gotoxy(di,14);cprintf(""); delay(200); } sleep(2); refresh: clrscr(); textcolor(8); gotoxy(35,1);cprintf("THE M%cGICI%cN", x2, x3); textcolor(15); gotoxy(27,2);cprintf(""); gotoxy(27,3);cprintf(" "); gotoxy(27,4);cprintf(""); gotoxy(27,5);cprintf(" "); gotoxy(27,6);cprintf(""); gotoxy(27,7);cprintf(" ");
[Link] AM [Link]

gotoxy(27,8);cprintf(""); gotoxy(27,9);cprintf(" "); gotoxy(27,10);cprintf(""); gotoxy(27,11);cprintf(" "); gotoxy(27,12);cprintf(""); gotoxy(27,13);cprintf(" "); gotoxy(27,14);cprintf(""); gotoxy(27,15);cprintf(" "); gotoxy(27,16);cprintf(" "); gotoxy(27,17);cprintf(" "); gotoxy(27,18);cprintf(""); gotoxy(37,2);cprintf(""); gotoxy(37,3);cprintf(" "); gotoxy(37,4);cprintf(""); gotoxy(37,5);cprintf(" "); gotoxy(37,6);cprintf(""); gotoxy(37,7);cprintf(" "); gotoxy(37,8);cprintf(""); gotoxy(37,9);cprintf(" "); gotoxy(37,10);cprintf(""); gotoxy(37,11);cprintf(" "); gotoxy(37,12);cprintf(""); gotoxy(37,13);cprintf(" "); gotoxy(37,14);cprintf(""); gotoxy(37,15);cprintf(" "); gotoxy(37,16);cprintf(" "); gotoxy(37,17);cprintf(" "); gotoxy(37,18);cprintf(""); gotoxy(47,2);cprintf(""); gotoxy(47,3);cprintf(" "); gotoxy(47,4);cprintf(""); gotoxy(47,5);cprintf(" "); gotoxy(47,6);cprintf(""); gotoxy(47,7);cprintf(" "); gotoxy(47,8);cprintf(""); gotoxy(47,9);cprintf(" "); gotoxy(47,10);cprintf(""); gotoxy(47,11);cprintf(" "); gotoxy(47,12);cprintf(""); gotoxy(47,13);cprintf(" "); gotoxy(47,14);cprintf(""); gotoxy(47,15);cprintf(" "); gotoxy(47,16);cprintf(" "); gotoxy(47,17);cprintf(" "); gotoxy(47,18);cprintf(""); textcolor(8); gotoxy(1,25);cprintf(" efresh"); textcolor(15); gotoxy(1,25);cprintf("R"); gotoxy(35,20);cprintf("Pick a card!"); gotoxy(32,21);cprintf("Enter which column!"); textcolor(7);
[Link] AM [Link]

gotoxy(33,17);cprintf("1"); gotoxy(43,17);cprintf("2"); gotoxy(53,17);cprintf("3"); textcolor(4); x=3; gotoxy(28,3);cprintf("K%c", x); gotoxy(28,7);cprintf("3%c", x); gotoxy(28,9);cprintf("Q%c", x); gotoxy(28,11);cprintf("6%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(28,15);cprintf("9%c", x); textcolor(8); x=5; gotoxy(48,7);cprintf("A%c", x2); gotoxy(28,5);cprintf("4%c", x2); gotoxy(38,3);cprintf("2%c", x); gotoxy(38,5);cprintf("J%c", x); gotoxy(38,7);cprintf("K%c", x); gotoxy(38,9);cprintf("8%c", x); gotoxy(38,13);cprintf("3%c", x); gotoxy(38,15);cprintf("5%c", x); textcolor(4); x=4; gotoxy(38,11);cprintf("7%c", x); gotoxy(48,3);cprintf("2%c", x); gotoxy(48,5);cprintf("9%c", x); gotoxy(48,9);cprintf("J%c", x); gotoxy(48,11);cprintf("Q%c", x); gotoxy(48,13);cprintf("5%c", x); gotoxy(48,15);cprintf("6%c", x); back: col=getch(); if(col=='1') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(28,15);cprintf("7%c", x); gotoxy(28,3);cprintf("2%c", x); gotoxy(38,3);cprintf("9%c", x); gotoxy(28,5);cprintf("J%c", x); gotoxy(38,5);cprintf("Q%c", x); gotoxy(48,5);cprintf("5%c", x); gotoxy(28,7);cprintf("6%c", x); textcolor(4); x=3;
[Link] AM [Link]

gotoxy(38,7);cprintf("K%c", x); gotoxy(28,9);cprintf("3%c", x); gotoxy(38,9);cprintf("Q%c", x); gotoxy(48,9);cprintf("6%c", x); gotoxy(28,11);cprintf("J%c", x); gotoxy(38,11);cprintf("9%c", x); textcolor(8); x=5; gotoxy(48,3);cprintf("A%c", x2); gotoxy(48,7);cprintf("4%c", x2); gotoxy(48,11);cprintf("2%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(38,13);cprintf("K%c", x); gotoxy(48,13);cprintf("8%c", x); gotoxy(38,15);cprintf("3%c", x); gotoxy(48,15);cprintf("5%c", x); back2: col2=getch(); if(col2=='1') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(38,11);cprintf("7%c", x); gotoxy(38,7);cprintf("2%c", x); gotoxy(48,11);cprintf("9%c", x); gotoxy(48,7);cprintf("J%c", x); gotoxy(28,13);cprintf("Q%c", x); gotoxy(38,3);cprintf("5%c", x); gotoxy(28,9);cprintf("6%c", x); textcolor(4); x=3; gotoxy(38,13);cprintf("K%c", x); gotoxy(38,9);cprintf("3%c", x); gotoxy(48,13);cprintf("Q%c", x); gotoxy(28,5);cprintf("6%c", x); gotoxy(48,9);cprintf("J%c", x); gotoxy(28,15);cprintf("9%c", x); textcolor(8); x=5; gotoxy(28,3);cprintf("A%c", x2); gotoxy(48,3);cprintf("4%c", x2); gotoxy(38,5);cprintf("2%c", x); gotoxy(28,11);cprintf("J%c", x); gotoxy(38,15);cprintf("K%c", x);
[Link] AM [Link]

gotoxy(48,5);cprintf("8%c", x); gotoxy(48,15);cprintf("3%c", x); gotoxy(28,7);cprintf("5%c", x); back3: col3=getch(); if(col3=='2') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("3%c", x); } else if(col3=='3') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("J%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back3; } else if(col2=='2') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(48,15);cprintf("7%c", x); gotoxy(48,11);cprintf("2%c", x); gotoxy(38,7);cprintf("9%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(48,7);cprintf("Q%c", x); gotoxy(38,3);cprintf("5%c", x); gotoxy(38,13);cprintf("6%c", x); textcolor(4); x=3; gotoxy(28,9);cprintf("K%c", x); gotoxy(48,13);cprintf("3%c", x); gotoxy(38,9);cprintf("Q%c", x);
[Link] AM [Link]

gotoxy(28,5);cprintf("6%c", x); gotoxy(28,15);cprintf("J%c", x); gotoxy(48,9);cprintf("9%c", x); textcolor(8); x=5; gotoxy(28,3);cprintf("A%c", x2); gotoxy(48,3);cprintf("4%c", x2); gotoxy(38,5);cprintf("2%c", x); gotoxy(38,15);cprintf("J%c", x); gotoxy(28,11);cprintf("K%c", x); gotoxy(48,5);cprintf("8%c", x); gotoxy(38,11);cprintf("3%c", x); gotoxy(28,7);cprintf("5%c", x); back4: col3=getch(); if(col3=='1') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("K%c", x); } else if(col3=='2') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("Q%c", x); } else if(col3=='3') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("9%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back4; } else if(col2=='3') {
[Link] AM [Link]

textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(48,15);cprintf("7%c", x); gotoxy(48,11);cprintf("2%c", x); gotoxy(28,3);cprintf("9%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(38,3);cprintf("Q%c", x); gotoxy(48,7);cprintf("5%c", x); gotoxy(38,13);cprintf("6%c", x); textcolor(4); x=3; gotoxy(48,3);cprintf("K%c", x); gotoxy(48,13);cprintf("3%c", x); gotoxy(28,5);cprintf("Q%c", x); gotoxy(38,9);cprintf("6%c", x); gotoxy(28,15);cprintf("J%c", x); gotoxy(38,5);cprintf("9%c", x); textcolor(8); x=5; gotoxy(38,7);cprintf("A%c", x2); gotoxy(28,9);cprintf("4%c", x2); gotoxy(48,9);cprintf("2%c", x); gotoxy(38,15);cprintf("J%c", x); gotoxy(48,5);cprintf("K%c", x); gotoxy(28,11);cprintf("8%c", x); gotoxy(28,7);cprintf("3%c", x); gotoxy(38,11);cprintf("5%c", x); back5: col3=getch(); if(col3=='1') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(8); gotoxy(46,13);cprintf("4%c", x2); } else if(col3=='2') { clrscr(); x=3; textcolor(15); gotoxy(31,13);cprintf("Your card is a");
[Link] AM [Link]

gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("6%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back5; } else if(col2=='r' || col2=='R') goto refresh; else goto back2; } else if(col=='2') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(48,9);cprintf("7%c", x); gotoxy(28,3);cprintf("2%c", x); gotoxy(38,3);cprintf("9%c", x); gotoxy(28,5);cprintf("J%c", x); gotoxy(38,5);cprintf("Q%c", x); gotoxy(48,5);cprintf("5%c", x); gotoxy(28,7);cprintf("6%c", x); textcolor(8); x=5; gotoxy(48,3);cprintf("A%c", x2); gotoxy(28,13);cprintf("4%c", x2); gotoxy(38,7);cprintf("2%c", x); gotoxy(48,7);cprintf("J%c", x); gotoxy(28,9);cprintf("K%c", x); gotoxy(38,9);cprintf("8%c", x); gotoxy(28,11);cprintf("3%c", x); gotoxy(38,11);cprintf("5%c", x); textcolor(4); x=3; gotoxy(48,11);cprintf("K%c", x); gotoxy(38,13);cprintf("3%c", x); gotoxy(48,13);cprintf("Q%c", x); gotoxy(28,15);cprintf("6%c", x); gotoxy(38,15);cprintf("J%c", x); gotoxy(48,15);cprintf("9%c", x); back6: col2=getch();

[Link] AM [Link]

if(col2=='1') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(28,5);cprintf("7%c", x); gotoxy(38,7);cprintf("2%c", x); gotoxy(48,11);cprintf("9%c", x); gotoxy(48,7);cprintf("J%c", x); gotoxy(28,13);cprintf("Q%c", x); gotoxy(38,3);cprintf("5%c", x); gotoxy(28,9);cprintf("6%c", x); textcolor(8); x=5; gotoxy(28,3);cprintf("A%c", x2); gotoxy(28,11);cprintf("4%c", x2); gotoxy(38,13);cprintf("2%c", x); gotoxy(48,3);cprintf("J%c", x); gotoxy(38,9);cprintf("K%c", x); gotoxy(48,13);cprintf("8%c", x); gotoxy(48,9);cprintf("3%c", x); gotoxy(28,15);cprintf("5%c", x); textcolor(4); x=3; gotoxy(38,5);cprintf("K%c", x); gotoxy(38,15);cprintf("3%c", x); gotoxy(48,5);cprintf("Q%c", x); gotoxy(38,11);cprintf("6%c", x); gotoxy(48,15);cprintf("J%c", x); gotoxy(28,7);cprintf("9%c", x); back7: col3=getch(); if(col3=='2') { clrscr(); x=5; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(8); gotoxy(46,13);cprintf("K%c", x); } else if(col3=='3') { clrscr(); x=5;
[Link] AM [Link]

textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(8); gotoxy(46,13);cprintf("3%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back7; } else if(col2=='2') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(28,5);cprintf("7%c", x); gotoxy(48,11);cprintf("2%c", x); gotoxy(38,7);cprintf("9%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(48,7);cprintf("Q%c", x); gotoxy(38,3);cprintf("5%c", x); gotoxy(38,13);cprintf("6%c", x); textcolor(8); x=5; gotoxy(28,3);cprintf("A%c", x2); gotoxy(38,15);cprintf("4%c", x2); gotoxy(28,9);cprintf("2%c", x); gotoxy(48,3);cprintf("J%c", x); gotoxy(48,13);cprintf("K%c", x); gotoxy(38,9);cprintf("8%c", x); gotoxy(28,15);cprintf("3%c", x); gotoxy(48,9);cprintf("5%c", x); textcolor(4); x=3; gotoxy(38,5);cprintf("K%c", x); gotoxy(28,11);cprintf("3%c", x); gotoxy(48,5);cprintf("Q%c", x); gotoxy(48,15);cprintf("6%c", x); gotoxy(38,11);cprintf("J%c", x); gotoxy(28,7);cprintf("9%c", x); back8: col3=getch(); if(col3=='1') { clrscr(); x=5;
[Link] AM [Link]

textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(8); gotoxy(46,13);cprintf("2%c", x); } else if(col3=='2') { clrscr(); x=5; textcolor(15); gotoxy(31,13);cprintf("Your card is an"); gotoxy(49,13);cprintf("!"); textcolor(8); gotoxy(47,13);cprintf("8%c", x); } else if(col3=='3') { clrscr(); x=5; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(8); gotoxy(46,13);cprintf("5%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back8; } else if(col2=='3') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=4; gotoxy(38,9);cprintf("7%c", x); gotoxy(48,11);cprintf("2%c", x); gotoxy(28,3);cprintf("9%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(38,3);cprintf("Q%c", x); gotoxy(48,7);cprintf("5%c", x); gotoxy(38,13);cprintf("6%c", x); textcolor(8); x=5; gotoxy(38,7);cprintf("A%c", x2); gotoxy(38,15);cprintf("4%c", x2); gotoxy(48,3);cprintf("2%c", x); gotoxy(28,9);cprintf("J%c", x);
[Link] AM [Link]

gotoxy(48,13);cprintf("K%c", x); gotoxy(28,5);cprintf("8%c", x); gotoxy(28,15);cprintf("3%c", x); gotoxy(38,5);cprintf("5%c", x); textcolor(4); x=3; gotoxy(48,9);cprintf("K%c", x); gotoxy(48,5);cprintf("3%c", x); gotoxy(28,11);cprintf("Q%c", x); gotoxy(48,15);cprintf("6%c", x); gotoxy(28,7);cprintf("J%c", x); gotoxy(38,11);cprintf("9%c", x); back9: col3=getch(); if(col3=='1') { clrscr(); x=5; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(8); gotoxy(46,13);cprintf("J%c", x); } else if(col3=='2') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("7%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back9; } else if(col2=='r' || col2=='R') goto refresh; else goto back6; } else if(col=='3') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=3;
[Link] AM [Link]

gotoxy(28,3);cprintf("K%c", x); gotoxy(48,3);cprintf("3%c", x); gotoxy(28,5);cprintf("Q%c", x); gotoxy(38,5);cprintf("6%c", x); gotoxy(48,5);cprintf("J%c", x); gotoxy(28,7);cprintf("9%c", x); textcolor(4); x=4; gotoxy(28,15);cprintf("7%c", x); gotoxy(38,7);cprintf("2%c", x); gotoxy(48,7);cprintf("9%c", x); gotoxy(38,9);cprintf("J%c", x); gotoxy(48,9);cprintf("Q%c", x); gotoxy(28,11);cprintf("5%c", x); gotoxy(38,11);cprintf("6%c", x); textcolor(8); x=5; gotoxy(28,9);cprintf("A%c", x2); gotoxy(38,3);cprintf("4%c", x2); gotoxy(48,11);cprintf("2%c", x); gotoxy(28,13);cprintf("J%c", x); gotoxy(38,13);cprintf("K%c", x); gotoxy(48,13);cprintf("8%c", x); gotoxy(38,15);cprintf("3%c", x); gotoxy(48,15);cprintf("5%c", x); back10: col2=getch(); if(col2=='1') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=3; gotoxy(38,7);cprintf("K%c", x); gotoxy(28,3);cprintf("3%c", x); gotoxy(48,7);cprintf("Q%c", x); gotoxy(28,13);cprintf("6%c", x); gotoxy(38,3);cprintf("J%c", x); gotoxy(28,9);cprintf("9%c", x); textcolor(4); x=4; gotoxy(38,11);cprintf("7%c", x); gotoxy(38,13);cprintf("2%c", x); gotoxy(48,3);cprintf("9%c", x); gotoxy(48,13);cprintf("J%c", x); gotoxy(28,5);cprintf("Q%c", x);
[Link] AM [Link]

gotoxy(48,9);cprintf("5%c", x); gotoxy(28,15);cprintf("6%c", x); textcolor(8); x=5; gotoxy(38,9);cprintf("A%c", x2); gotoxy(48,11);cprintf("4%c", x2); gotoxy(38,5);cprintf("2%c", x); gotoxy(28,11);cprintf("J%c", x); gotoxy(38,15);cprintf("K%c", x); gotoxy(48,5);cprintf("8%c", x); gotoxy(48,15);cprintf("3%c", x); gotoxy(28,7);cprintf("5%c", x); back11: col3=getch(); if(col3=='2') { clrscr(); x=5; textcolor(15); gotoxy(31,13);cprintf("Your card is an"); gotoxy(49,13);cprintf("!"); textcolor(8); gotoxy(47,13);cprintf("A%c", x2); } else if(col3=='3') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("5%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back11; } else if(col2=='2') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=3; gotoxy(48,11);cprintf("K%c", x); gotoxy(28,3);cprintf("3%c", x); gotoxy(28,13);cprintf("Q%c", x); gotoxy(48,7);cprintf("6%c", x);
[Link] AM [Link]

gotoxy(38,3);cprintf("J%c", x); gotoxy(38,13);cprintf("9%c", x); textcolor(4); x=4; gotoxy(48,15);cprintf("7%c", x); gotoxy(28,9);cprintf("2%c", x); gotoxy(48,3);cprintf("9%c", x); gotoxy(38,9);cprintf("J%c", x); gotoxy(28,5);cprintf("Q%c", x); gotoxy(28,15);cprintf("5%c", x); gotoxy(48,9);cprintf("6%c", x); textcolor(8); x=5; gotoxy(48,13);cprintf("A%c", x2); gotoxy(38,7);cprintf("4%c", x2); gotoxy(38,5);cprintf("2%c", x); gotoxy(38,15);cprintf("J%c", x); gotoxy(28,11);cprintf("K%c", x); gotoxy(48,5);cprintf("8%c", x); gotoxy(38,11);cprintf("3%c", x); gotoxy(28,7);cprintf("5%c", x); back12: col3=getch(); if(col3=='1') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("2%c", x); } else if(col3=='2') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("J%c", x); } else if(col3=='3') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4);
[Link] AM [Link]

gotoxy(46,13);cprintf("6%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back12; } else if(col2=='3') { textcolor(8); gotoxy(33,23);cprintf("shuffling cards..."); sleep(2); textcolor(15); gotoxy(35,20);cprintf("Where is it?"); gotoxy(33,23);cprintf(" "); textcolor(4); x=3; gotoxy(48,11);cprintf("K%c", x); gotoxy(38,7);cprintf("3%c", x); gotoxy(28,13);cprintf("Q%c", x); gotoxy(38,3);cprintf("6%c", x); gotoxy(48,7);cprintf("J%c", x); gotoxy(38,13);cprintf("9%c", x); textcolor(4); x=4; gotoxy(48,15);cprintf("7%c", x); gotoxy(48,3);cprintf("2%c", x); gotoxy(28,9);cprintf("9%c", x); gotoxy(28,5);cprintf("J%c", x); gotoxy(38,9);cprintf("Q%c", x); gotoxy(28,15);cprintf("5%c", x); gotoxy(38,5);cprintf("6%c", x); textcolor(8); x=5; gotoxy(48,13);cprintf("A%c", x2); gotoxy(28,3);cprintf("4%c", x2); gotoxy(48,9);cprintf("2%c", x); gotoxy(38,15);cprintf("J%c", x); gotoxy(48,5);cprintf("K%c", x); gotoxy(28,11);cprintf("8%c", x); gotoxy(28,7);cprintf("3%c", x); gotoxy(38,11);cprintf("5%c", x); back13: col3=getch(); if(col3=='1') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!");
[Link] AM [Link]

textcolor(4); gotoxy(46,13);cprintf("9%c", x); } else if(col3=='2') { clrscr(); x=4; textcolor(15); gotoxy(31,13);cprintf("Your card is a"); gotoxy(48,13);cprintf("!"); textcolor(4); gotoxy(46,13);cprintf("Q%c", x); } else if(col3=='r' || col3=='R') goto refresh; else goto back13; } else if(col2=='r' || col2=='R') goto refresh; else goto back10; } else if(col=='r' || col=='R') goto refresh; else goto back; sleep(2); clrscr(); textcolor(4); gotoxy(37,13);cprintf("THE END!"); } else if(cho=='c' || cho=='C') { clrscr(); textcolor(8); gotoxy(1,5);cprintf(" nspired by: afael artin's magic"); gotoxy(1,25);cprintf(" ress any key to exit"); textcolor(15); gotoxy(1,1);cprintf("P"); gotoxy(13,1);cprintf("E"); gotoxy(20,1);cprintf("L"); gotoxy(1,3);cprintf("S"); gotoxy(20,3);cprintf("J"); gotoxy(25,3);cprintf("J"); gotoxy(1,5);cprintf("I"); gotoxy(14,5);cprintf("R"); gotoxy(21,5);cprintf("M"); gotoxy(1,25);cprintf("P"); gotoxy(22,25);cprintf("..."); getch(); goto intro; } else
[Link] AM [Link]

goto intro; return 0; }

[Link] AM [Link]

// Program to design a Five Function Calculator using Switch/Case #include <iostream.h> #include <conio.h> int main () { main: int a,b,c,d,ans; double v1, v2, ans2; char yn; while (yn != 'n') { clrscr(); cout<<"\n\n\n\t-_-_-_-_-_-_-_-_- Five Function Calculator _-_-_-_-_-_-_-_-_\n\n"; cout<<"Select the operation .\n"; cout<<"1. Multipication\n"; cout<<"2. Division\n"; cout<<"3. Subtraction\n"; cout<<"4. Addition\n"; cout<<"5. Power\n"; cout<<"6. Exit\n"; cout<<"Enter a number: [1-6]"; cin>>ans; switch (ans) { case 1: goto multipication; break; case 2: goto division; break; case 3: goto subtraction; break; case 4: goto addition; break; case 5: goto power; break; case 6: cout<<"Thank You\n"; return 0; } multipication: cout<<"\n\t\t==================Multipication===============\n"; cout<<"Enter your First Number: "; cin>>v1; cout<<"Enter your Second Number: "; cin>>v2; ans2=v1 * v2; cout<<"Answer: "<<ans2<<"\n\n"; cout<<"Would like to solve another one <yn>: "; cin>>yn;

[Link] AM [Link]

goto main; return 0; division: cout<<"\n\t\t==================Division===============\n"; cout<<"Enter your First Number: "; cin>>v1; cout<<"Enter your Second Number: "; cin>>v2; if (v2==0) { cout<<"ERROR!!! You cannot divide anything by 0\n\n"; goto main; } ans2=v1 / v2; cout<<"Answer: "<<ans2<<"\n\n"; cout<<"Would like to solve another one <yn>: "; cin>>yn; goto main; return 0; subtraction: cout<<"\n\t\t==================Subtraction===============\n"; cout<<"Enter your First Number: "; cin>>v1; cout<<"Enter your Second Number: "; cin>>v2; ans2=v1 - v2; cout<<"Answer: "<<ans2<<"\n\n"; cout<<"Would like to solve another one <yn>: "; cin>>yn; goto main; return 0; addition: cout<<"\n\t\t==================Addition===============\n"; cout<<"Enter your First Number: "; cin>>v1; cout<<"Enter your Second Number: "; cin>>v2; ans2=v1 + v2; cout<<"Answer: "<<ans2<<"\n\n"; cout<<"Would like to solve another one <yn>: "; cin>>yn; goto main; return 0; power: cout<<"\n\t\t==================Power===============\n"; cout<<"Enter a number: "; cin>>v1; cout<<"Enter the Power: "; cin>>v2; ans2=v1; for(int i=2; i<=v2; i++) ans2 = ans2 * v1; cout<<"Answer: "<<ans2<<"\n\n";
[Link] AM [Link]

cout<<"Would like to solve another one <yn>: "; cin>>yn; goto main; return 0; } return 0; }

[Link] AM [Link]

// Conversion program using Fucntions. #include <iostream.h> #include <stdlib.h> char choosestd; float inch1; float inch2; float foot; float yard; float mile; float millimeter; float centimeter; float meter1; float meter2; float kilometer; int first; float firstfunction(); float secondfunction(); float thirdfunction(); float fourthfunction(); float fifthfunction(); float sixthfunction(); float seventhfunction(); float eigthfunction(); float ninthfunction(); float tenthfunction(); int main() { clrscr(); cout << "*-------------------------------------------------------------*\n"; cout << " \n\n\n"; cout << "To (q)uit any time type enter \"q\"\n\n"; cout << "To convert from Standard Measurments to Metric enter \"1\": \n"; cout << "To convert from Metric to Standard Measurments enter \"2\": \n"; cin >> first; if (first == 1) { int choosestd; cout << "What would you like to convert?\n"; cout << "(1)Inches to Millimeters: \n"; cout << "(2)Inches to Centimeters: \n"; cout << "(3)Feet to Meters: \n"; cout << "(4)Yards to Meters: \n"; cout << "(5)Miles to Kilometers: \n"; cin >> choosestd; if (choosestd == 1) { cout << "\nEnter the number of inches you wish converted: \n";

[Link] AM [Link]

cin >> inch1; cout << "You entered " << inch1 ; cout<< " inches, which equals " << firstfunction() << " millimeters.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 2) { cout << "\nEnter the number of inches you wish converted: \n"; cin >> inch2; cout << "You entered " << inch2 << " inches, which equals " << secondfunction() << " centimeters.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 3) { cout << "\nEnter the number of feet you wish converted: \n"; cin >> foot; cout << "You entered " << foot << " feet, which equals " << thirdfunction() << " meters.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 4) { cout << "\nEnter the number of yards you wish converted: \n"; cin >> yard; cout << "You entered " << yard << " yards, which equals " << fourthfunction() << " meters.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 5) { cout << "\nEnter the number of miles you wish converted: \n"; cin >> mile; cout << "You entered " << mile << " miles, which equals " << fifthfunction() << " kilometers.\n\n"; system("PAUSE"); return main(); } else if ((choosestd != 1) || (choosestd !=2) || (choosestd !=3) || (choosestd !=4) || (choosestd !=5)) { cout<<endl; cout << "\n\nThank you for using this program.\n\n"; cout<<"endl";
[Link] AM [Link]

getch(); return 0; } } else if (first == 2) { int choosestd; cout << "What would you like to convert?\n"; cout << "(1)Millimeters to Inches: \n"; cout << "(2)Centimeters to Inches: \n"; cout << "(3)Meters to Feet: \n"; cout << "(4)Meters to Yards: \n"; cout << "(5)Kilometers to Miles: \n"; cin >> choosestd; if (choosestd == 1) { cout << "\nEnter the number of millimeters you wish converted: \n"; cin >> millimeter; cout << "You entered " << millimeter << " millimeters, which equals " << sixthfunction() << " inches.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 2) { cout << "\nEnter the number of centimeters you wish converted: \n"; cin >> centimeter; cout << "You entered " << centimeter << " centimeters, which equals " << seventhfunction() << " inches.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 3) { cout << "\nEnter the number of meters you wish converted: \n"; cin >> meter1; cout << "You entered " << meter1 << " meters, which equals " << eigthfunction() << " feet.\n\n"; system("PAUSE"); return main(); } else if (choosestd == 4) { cout << "\nEnter the number of meters you wish converted: \n"; cin >> meter2; cout << "You entered " << meter2 << " meters, which equals " << ninthfunction() << " yards.\n\n";
[Link] AM [Link]

system("PAUSE"); return main(); } else if (choosestd == 5) { cout << "\nEnter the number of kilometers you wish converted: \n"; cin >> kilometer; cout << "You entered " << kilometer << " kilometers, which equals " << tenthfunction() << " miles.\n\n"; system("PAUSE"); return main(); } else if ((choosestd != 1) || (choosestd !=2) || (choosestd !=3) || (choosestd !=4) || (choosestd !=5)) { int x; cout << "\n\nThank you for using this program.\n\n"; cin >> x; return 0; } }

else if ((first != 1) || (first != 2)) { int x; cout << "End Program.\n\n\nThis program was brought to you by\n cout << "Thank you\n\n\n"; cin >> x; return 0; } } float firstfunction() { double x; x = (inch1 * 25.4); return x; } float secondfunction() { double x; x = (inch2 * 2.54); return x; } float thirdfunction() { float x; x = (foot * .3048);
[Link] AM [Link]

[Link]

return x; } float fourthfunction() { float x; x = (yard * .9144); return x; } float fifthfunction() { float x; x = (mile * 1.609); return x; } float sixthfunction() { float x; x = (millimeter / 25.4); return x; } float seventhfunction() { float x; x = (centimeter / 2.54); return x; } float eigthfunction() { float x; x = (meter1 / .3048); return x; } float ninthfunction() { float x; x = (meter2 / .9144); return x; } float tenthfunction() { float x; x = (kilometer / 1.609); return x; }

[Link] AM [Link]

// Program to display all prime fibonacci series within the // range of 1 to 10000. #include<conio.h> #include<iostream.h> #include<stdio.h> int isprime(int); main() { clrscr(); cout<<"All prime fibonacci series in the range of 1 to 10000 are"<<endl; int r; int a=1,b=2,c=0; r=isprime(a); if (r==1) cout<<a<<" "; r=isprime(b); if (r==1) cout<<b<<" "; while (c<=10000) { c=a+b; r=isprime(c); if ((r==1) && (c<=10000)) cout<<c<<" "; a=b; b=c; } getch(); } int isprime(int x) { int i; if (x==1) return 0; else { int p=1; for(i=2;i<x;i++) { if (x%i==0) p=2; } return (p); } }

[Link] AM [Link]

// Program to display a Triangle of numbers called the // Pascal's Triangle, when provided with // the number of rows. # include <stdio.h> #include<conio.h> void main () { int pal[50][50]; int i,j,k,n; printf("ENTER THE NUMBER OF ROWS : "); scanf("%d",&n); for (i=0;i<n;i++) { pal[i][0]=1; pal[i][i]=1; for (j=1;j<i;j++) { pal[i][j]=pal[i-1][j-1]+pal[i-1][j]; } for (j=1;j<=(n-(i+1));j++) { printf (" "); } for (k=0;k<=i;k++) { printf(" %2d ",pal[i][k]); } printf("\n"); } getch(); }

[Link] AM [Link]

// Program to input any string and print the number of spaces stored // within the string at prime positions. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> main() { char a,name[50]; int f=0, l=0,c=0,k=0; cout<<"Enter any string "<<endl; gets(name); l = strlen(name); cout<<"The length of the string is "<<l; cout<<endl; for(int i=0;i<l;i++) { a=name[i]; if (a==' ') // checking if i is prime k=i+1; for(int l=1;l<=k;l++) { if (k%l==0) f=f+1; } if (f==2) c = c + 1; f=0; } cout<<endl<<"The no. of spaces at prime position is "<<c; getch(); return 0; }

[Link] AM [Link]

// Program for Pig Latin Converter #include #include #include #include <iostream.h> <string.h> <stdio.h> <conio.h>

int makePhrase(char * word, char phrase[][20]); void main() { clrscr(); char word[30] = {'\0'}; char phrase[20][20]; char convert[30] = {'\0'}; char temp[10] = {'\0'}; int counter =0; int check = 0; int firstvowel = 0; int i; int numcons; cout<<"Please enter a word or phrase up to 30 characters"<<endl; [Link](word,30,'\n'); strlwr(word); cout<<"\nYour entry was '"<<word<<"'"<<endl; cout<<"---------------------------"<<endl; i=makePhrase(word,phrase); for (int k=0; k<i; k++) { int size = strlen(phrase[k]); for(int j=0;j<size;j++) { switch(phrase[k][j]) { case 'a': if (j == 0) firstvowel = 1; check = 1; break; case 'e': if (j == 0) firstvowel = 1; check = 1; break; case 'i':

[Link] AM [Link]

if (j == 0) firstvowel = 1; check = 1; break; case 'o': if (j == 0) firstvowel = 1; check = 1; break; case 'u': if (j == 0) firstvowel = 1; check = 1; break; default: if (check != 1 && firstvowel != 1) counter++; break; } }; if (firstvowel == 1) { strcat(phrase[k],"hay"); cout<<"Word begins with a vowel, no need for movement"<<endl; cout<<"Your word in Pig Latin is\n"<<phrase[k]<<endl; cout<<"---------------------------"<<endl; } else { numcons = counter-1; cout<<"The first vowel is: "<<phrase[k][counter]<<endl; cout<<"The letter(s) to move is:"<<endl; do { cout<<phrase[k][numcons]<<endl; temp[numcons] = phrase[k][numcons];

numcons-=1; }while(numcons !=-1); int leftover = strlen(phrase[k]) - numcons; for(int i=0; i<leftover; i++) { convert[i] = phrase[k][counter]; counter+=1;
[Link] AM [Link]

}; strcat(convert, temp); strcat(convert, "ay"); strcpy(phrase[k],convert); cout<<"Your word in Pig Latin is:\n"<<phrase[k]<<endl; cout<<"---------------------------"<<endl; }; numcons=0; counter=0; firstvowel=0; size=0; check = 0; strcpy(temp,"0"); };

cout<<"\n\nYour translated entry:\n"; cout<<"--------------\n"; for(int a=0;a<i;a++) { cout<<phrase[a]<<" "; }; cout<<"\n--------------"<<endl; }; int makePhrase(char * word, char phrase[][20]) { int i=0; char *space = " "; char *breaker; breaker = strtok(word,space); while ( breaker ) { strcpy( phrase[i],breaker ); breaker = strtok( NULL, space ); i++; }; return i; };

[Link] AM [Link]

// The program calculates the value of a polynomial #include <iostream.h> #include <conio.h> #include <process.h> const int MAXDEGREE = 10; // define constant

void main() { float x, y; float coefficients[MAXDEGREE+1]; // coefficients of a polynomial float x_powers[MAXDEGREE+1]; // powers of x int degree, i; cout << "\nCalculation of polynomial"; cout << "\nEnter degree "; cin >> degree; if (degree > MAXDEGREE || degree < 0) { cout << "\nError"; getch(); exit(0); } // read coefficients, highest first: for (i = degree; i >= 0; i--) { cout << "\nEnter coefficient " << i << " "; cin >> coefficients[i]; } // read x: cout << "\nEnter x "; cin >> x; // calculate powers of x x_powers[0] = 1; for (i=1; i <= degree; i++) { x_powers[i] = x_powers[i-1] * x; } // calculate polynomial y = 0; for (i = 0; i <= degree; i++) { y = y + coefficients[i] * x_powers[i]; } // write result cout << "\n\nResult is " << y; // wait for key pressure and exit getch();

[Link] AM [Link]

[Link] AM [Link]

// Program to assign string in a double dimensional array and display // the contents. #include <iostream.h> #include <conio.h> enum {NAMESIZE=20}; // Print out the first n names of a void printNames(char a[][NAMESIZE], int n) { for (int row=0; row<n; row++) { for (int clmn=0; a[row][clmn] != '\0'; clmn++) { cout << a[row][clmn]; } cout << endl; } } // Print out the first n names of a void printNames(char *a[], int n) { for (int k=0; k<n; k++) { cout << a[k] << endl; } } void main(void) { char names1[][NAMESIZE] = {"ankur", "rose", "simran", "gauri"}; char *names2[] = {"lallan", "ballan", "sonal", "monika"}; cout << "The size of names1 is " << sizeof(names1) << endl; cout << "The size of names2 is " << sizeof(names2) << endl; getch(); cout << endl << "Printing out: char names1[][NAMESIZE]" << endl; printNames(names1, 4); cout << endl << "Printing out: char *names[]" << endl; printNames(names2, 4); getch(); cout << endl << "Printing out: names1[row]" << endl; for (int row=0; row < 4; row++) { cout << names1[row] << endl; }

[Link] AM [Link]

cout << endl << "Printing out: names2[row]" << endl; for (row=0; row < 4; row++) { cout << names2[row] << endl; } getch();clrscr(); }

[Link] AM [Link]

// Program to print the product of two matrices #include<iostream.h> #include<conio.h> main() { clrscr(); int i,j,a[3][4],b[4][3],c[3][3]; //Creation of matrix A[3][4] cout<<"Enter elements of array A"<<endl; for(i=0;i<3;i++) { for(j=0;j<4;j++) { cin>>a[i][j]; } } cout<<"Enter elements of array B"<<endl; for(i=0;i<4;i++) { for(j=0;j<3;j++) { cin>>b[i][j]; } } // storing product in array C for (i=0;i<3;i++) { for (j=0;j<3;j++) { c[i][j]=0; for(int k=0;k<4;k++) { c[i][j]=a[i][k]*b[k][j]+c[i][j]; } } } cout<<endl<<"The matrix A is "<<endl; for(i=0;i<3;i++) { for(j=0;j<4;j++) { cout<<a[i][j]<<" "; } cout<<endl; } cout<<endl<<"The matrix B is "<<endl; for(i=0;i<4;i++) { for(j=0;j<3;j++) { cout<<b[i][j]<<" "; }

[Link] AM [Link]

cout<<endl; } cout<<endl<<"The matrix C is "<<endl; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<c[i][j]<<" "; } cout<<endl; } getch(); return 0; }

[Link] AM [Link]

// Program for converting an int variable to floating point #include <iostream.h> #include <stdlib.h> //defines EXIT_SUCCESS etc #include <conio.h> int main( void ) { // declare variables here int x,y; float quotient; cout <<"enter an integer x="; cin >> x; cout <<"enter an integer y="; cin >> y; quotient= x / y; cout<< "x / y is " << quotient << endl; quotient= float(x) / y; cout<< "float(x) / y is " << quotient << endl; getch(); return EXIT_SUCCESS; }

[Link] AM [Link]

//Program to play a puzzle #include<graphics.h> #include<iostream.h> #include<conio.h> #include<dos.h> #include<string.h> #include<stdio.h> getkey1() {union REGS i,o; while(!kbhit()); [Link]=0; int86(22,&i,&o); return([Link]); } void main2() {int gd=DETECT,gm,i,j,n=0,m,q=0,v=0,k; char *a[16]={"9","3","2","4","7","6","5","8","1","11" ,"13","12","10","14"," " ,"15"} ,*b[16]={"1","2","3","4","5","6","7","8","9","10" ,"11","12","13","14","15" ," "},*t; initgraph(&gd,&gm,"c:\\tc\\bgi"); setcolor(3); outtextxy(260,100," PUZZLE"); setcolor(4); setcolor(WHITE); delay(2000); for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,a[n]); n++; } do{{ setcolor(3); outtextxy(100,170,"YOU HAVE TO SOLVE IT WITHIN 400 MOVES"); setcolor(8); outtextxy(280,130,"LEVEL: 2 "); setcolor(9); outtextxy(100,150,"YOU HAVE SPENT "); //outtextxy(220,150,v); gotoxy(28,10); cout<<v; outtextxy(240,150," MOVES "); setcolor(2); outtextxy(100,330,"USE ARROW KEYS FOR DIRECTION"); setcolor(4); outtextxy(200,350,"PRESS '* ' TO QUIT AT ANY TIME"); setcolor(5); outtextxy(400,50,"ARRANGE LIKE THIS"); m=0; for(i=425;i<=500;i+=25) for(j=60;j<=135;j+=25)

[Link] AM [Link]

{rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,b[m]); m++; } } setcolor(WHITE); if((*a[0]=='1')&&(*a[1]=='2')&&(*a[2]=='3')&&(*a[3]=='4')&&(*a[4]=='5')&&(*a[5]=='6')&&(*a[6]=='7')&&(*a[7]= ='8') && (*a[8]=='9')&&(strcmp(a[9],"10")==0)&&(strcmp(a[10],"11")==0)&&(strcmp(a[11],"12")==0)&&(strcmp(a[12],"13") ==0)&&(strcmp(a[13],"14")==0)&&(strcmp(a[14],"15")==0)) {setcolor(5); outtextxy(200,350,"CONGRATULATION! YOU WIN"); getch(); break; } k=getkey1(); sound(500); delay(100); nosound(); switch(k) {case 75:{clearviewport(); n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&(n<=11)&&(q==0)) {t=a[n]; a[n]=a[n+4]; a[n+4]=t; q=1; v++; } n++; } n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,a[n]); n++; } q=0; break; } case 77:{clearviewport(); n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&(n>3)&&(q==0)) {t=a[n]; a[n]=a[n-4]; a[n-4]=t; q=1;
[Link] AM [Link]

v++; } n++; } n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,a[n]); n++; } q=0;break; } case 80: {clearviewport(); n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&((n!=0)&&(n!=4)&&(n!=8)&&(n!=12))&&(q==0)) {t=a[n]; a[n]=a[n-1]; a[n-1]=t; q=1; v++; } n++; } n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,a[n]); n++; } q=0;break; } case 72:{clearviewport(); n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&(n!=3)&&(n!=7)&&(n!=11)&&(n!=15)&&(q==0)) {t=a[n]; a[n]=a[n+1]; a[n+1]=t; q=1; v++; } n++; } n=0; for(i=250;i<=325;i+=25) for(j=200;j<=275;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,a[n]); n++; }
[Link] AM [Link]

q=0; break; } }}while((k!=55)&&(v<=400)); if(v>400) {outtextxy(200,350,"SORRY! YOUR MOVE IS OVER"); getch(); } closegraph(); } //[Link] ends here.

#include<graphics.h> #include<iostream.h> #include<conio.h> #include<dos.h> #include<string.h> #include<stdio.h> getkey() {union REGS i,o; while(!kbhit()); [Link]=0; int86(22,&i,&o); return([Link]); } void main() {int gd=DETECT,gm,i,j,n=0,m,q=0,v=0,k; char *a[9]={"7","2","5","4","3","6","1"," ","8"} ,*b[9]={"1","2","3","4","5","6","7","8"," "},*t; initgraph(&gd,&gm,"..//bgi"); setcolor(3); outtextxy(260,100," PUZZLE"); setcolor(4); setcolor(WHITE); delay(2000); for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,a[n]); n++; } do{{ setcolor(3); outtextxy(100,170,"YOU HAVE TO SOLVE IT WITHIN 200 MOVES"); setcolor(1); outtextxy(210,130,"LEVEL : 1"); setcolor(9); outtextxy(100,150,"YOU HAVE SPENT "); //outtextxy(220,150,v); gotoxy(28,10); cout<<v;
[Link] AM [Link]

outtextxy(240,150," MOVES "); setcolor(2); outtextxy(100,330,"USE ARROW KEYS FOR DIRECTION"); setcolor(4); outtextxy(100,350,"PRESS '* ' TO QUIT AT ANY TIME"); setcolor(5); outtextxy(400,50,"ARRANGE LIKE THIS"); m=0; for(i=425;i<=475;i+=25) for(j=60;j<=110;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+8,j+10,b[m]); m++; } } setcolor(WHITE); if((*a[0]=='1')&&(*a[1]=='2')&&(*a[2]=='3')&&(*a[3]=='4')&&(*a[4]=='5')&&(*a[5]=='6')&&(*a[6]=='7')&&(*a[7]= ='8')) {setcolor(5); outtextxy(180,380,"CONGRATULATION! YOU FINISHED LEVEL 1"); getch(); clearviewport(); main2(); break; } k=getkey(); sound(300); delay(100); nosound(); switch(k) {case 75:{clearviewport(); n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&(n<=5)&&(q==0)) {t=a[n]; a[n]=a[n+3]; a[n+3]=t; q=1; v++; } n++; } n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+10,j+10,a[n]); n++; }
[Link] AM [Link]

q=0; break; } case 77:{clearviewport(); n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&(n>=2)&&(q==0)) {t=a[n]; a[n]=a[n-3]; a[n-3]=t; q=1; v++; } n++; } n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+10,j+10,a[n]); n++; } q=0;break; } case 80: {clearviewport(); n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&((n!=0)&&(n!=3)&&(n!=6))&&(q==0)) {t=a[n]; a[n]=a[n-1]; a[n-1]=t; q=1; v++; } n++; } n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+10,j+10,a[n]); n++; } q=0;break; } case 72:{clearviewport(); n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); if ((*a[n]==' ')&&((n!=2)&&(n!=5)&&(n!=8))&&(q==0)) {t=a[n]; a[n]=a[n+1];
[Link] AM [Link]

a[n+1]=t; q=1; v++; } n++; } n=0; for(i=200;i<=250;i+=25) for(j=200;j<=250;j+=25) {rectangle(i,j,i+25,j+25); outtextxy(i+10,j+10,a[n]); n++; } q=0; break; } }}while((k!=55)&&(v<=200)); if(v>200) {outtextxy(200,350,"SORRY! YOUR MOVE IS OVER"); delay(2000); getch(); } closegraph(); }

[Link] AM [Link]

// Program to print out a checkered board of size n #include <iostream.h> #include <conio.h> const int cellSize = 4; void printnc(char c, int n){ for(int k = 0; k<n; ++k) cout << c; } void printBWcells(void){ printnc('.', cellSize); printnc(' ', cellSize); } void printWBcells(void){ printnc(' ', cellSize); printnc('.', cellSize); } void printBoard(int n){ printnc('*', 2+2*n*cellSize); cout << endl; for(int k = 0; k<n; ++k){ for(int h = 0; h < cellSize; ++h){ cout << '*'; for(int m=0; m<n; ++m){ if((k%2)==0) printBWcells(); else printWBcells(); } cout << '*' << endl; } } printnc('*', 2+2*n*cellSize); cout << endl; } void main(void){ int n; clrscr(); cout << "Enter size of board: "; cin >> n; clrscr(); printBoard(n); cout<<endl; cout<<"Press any key to continue"; getch(); }

[Link] AM [Link]

[Link] AM [Link]

// Program to Print out a diamond of any size less than 12 #include <iostream.h> #include <conio.h> const int Center = 20; void printnc(char c, int n){ for (int lcv=0; lcv < n; lcv++) { cout << c; } } // Print out a triangle of size n void printTriangle(int n){ for (int i=0; i < n; i++){ printnc(' ', Center - i -1); printnc('X', 2*i+1); cout << endl; } } // Print reverse of triangle printed by printTriangle void printRTriangle(int n){ for (int i=0; i < n; i++){ printnc(' ', Center - n + i); printnc('X', 2*n-2*i-1); cout << endl; } } // Get dimension of triangle from user void main(void){ int m; cout << "Enter an integer m [0 < m < 12]: "; endl; cin >> m; while ((m > 0) && (m < 12)){ printTriangle(m); printRTriangle(m-1); cout << "Enter an integer m [0 < m < 12]: "; cin >> m; } }

[Link] AM [Link]

// Program to implement a Recursive Function #include <iostream.h> #include <string.h> #include <stdlib.h> #include <conio.h> void recurfunc(int start,int stop,char* buff); void main() { clrscr(); cout << "enter how many times to loop: "; char buff[100]; cin >> buff; int num; num = atoi(buff); if(num >= 1) { recurfunc(0,num," this is a recursive function"); } else { cout << "sorry you didnt enter valid data" << endl; return; } getch(); } void recurfunc(int start,int stop,char* buff) { if(start < stop) { start++; cout << "\n" << buff << "\n"; recurfunc(start,stop,buff); } else { return; } }

[Link] AM [Link]

// Program to delete the first common word in two strings // and display the strings without the first common words. #include <conio.h> #include <stdio.h> #include <iostream.h> char string1[25] = {'\0'}; char string2[25] = {'\0'}; char temp[25] = {'\0'}; int start = -1; int end = -1; int start2 = 0; int end2 = 0; /*GET THE INPUT FOR THE STRINGS*/ void get_input() { cout << "Enter the first string : "; gets(string1); cout << "Enter the second string : "; gets(string2); } /*SET INDEXES FOR ALIAS WORD*/ void extract_word() { while( string2[end2] != ' ' ) end2++; } /*COMPARE THE TWO WORDS*/ int compare() { int n; for(n=start; n<end; n++) { if( string2[n-start] != string1[n] ) { return 0; } } return 1; }

[Link] AM [Link]

/*FIND THE ALIAS WORD IN THE STRINGS*/ void find_alias() { int same = 0; while( (same != 1) && (string1[end] != '\0') ) { end++; start = end; while( (string1[end] != ' ') && (string1[end] != '\0') ) end++; same = compare(); } } /*REPLACE THE WORD*/ void replace_alias() { int counter = end; /*find the end of the string*/ while( string1[counter] != '\0' ) counter++; /*copy the remaining string to temp*/ for(int i=end; i<counter; i++) { temp[i-end] = string1[i]; } counter = start; /*nullify the remaining string*/ while( string1[counter] != '\0' ) { string1[counter] = '\0'; counter++; } start2 = end2; counter = start-1; /*replace the alias by the second string*/ while( string2[end2] != '\0' ) { string1[counter] = string2[end2]; end2++; counter++; } int k = 0;
[Link] AM [Link]

/*copy the remaining string back from temp*/ while( temp[k] != '\0' ) { string1[counter] = temp[k]; k++; counter++; } } void main() { clrscr(); get_input(); extract_word(); find_alias(); replace_alias(); cout << string1 << '\n'; getch(); }

[Link] AM [Link]

// Program to input any string and print the number of words. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> main() { char a,name[50]; int l=0,c=0,word=0; cout<<"Enter any string "<<endl; gets(name); l = strlen(name); cout<<endl; for(int i=0;i<l;i++) { a=name[i]; if (a==' ') c = c + 1; } word = c + 1; cout<<"The total number of words in the string is "<<word; cout<<endl; getch(); return 0; }

[Link] AM [Link]

// Rotates a word //This program prints all the rotation of a word. //Say if the input word is "space", then it prints //space //paces //acesp //cespa //espac #include <stdio.h> #include <string.h> #include <conio.h> void main() { char w[50],buf[50],temp[50],buf2[10]; clrscr(); printf("Enter a word to see it's rotation :"); fflush(stdin); gets(w); strcpy(temp,w); printf("All the rotation of the word \"%s\" are :",w); for(int i=0;i<strlen(w);i++) { strcpy(buf,strnset(w,' ',i)); for(int j=0;j<i;j++) buf2[j]=temp[j]; buf2[j]='\0'; strcat(buf,buf2); //To straighten the output gotoxy(strlen(w)-i,4+i); puts(buf); } getch(); }

[Link] AM [Link]

// This function allows the user to enter a number // and than rounds it off, // correct to the nearest integer. #include <iostream.h> #include <conio.h> void main() { clrscr(); //HEADER FILES // MAIN FUNCTION // CLEAR THE SCREEN

float input=0,remainder=0; // INITIALIZATION AND DECLARATION OF int whole=0,answer=0; // VARIABLES gotoxy (15,15); // GO TO A PARTICULAR POSITION // MESSAGE

cout << "ENTER A FLOAT NUMBER : "; cin >> input;

// STORE THE INPUT INTO THE VARIABLE

whole = input; // THIS LINE STORES THE INTEGER PART OF THE VALUE // INTO A SEPERATE VARIABLE remainder = input - whole; // REMAINDER IS THE VALUE AFTER THE DECIMAL // POINT if (remainder >= 0.5) answer = whole + 1; else // IF REMAINDER IS GREATER THAN 0.5 // ADD 1 TO THE VALUE

// OTHERWISE // KEEP THE INTEGER PART AS IT IS

answer = whole;

gotoxy (15,16); cout << "Rounded Off Number Is : " << answer; // DISPLAY THE ANSWER getch(); } // WAIT FOR AN INPUT FROM THE USER.

// END OF FUNCTION

[Link] AM [Link]

// Array sorting // Using Selection Sorting Technique. // Program to input any ten numbers and print them in ascending order. #include<iostream.h> #include<conio.h> main() { int number[10],a,b,c,d; clrscr(); // clear the screen cout<<"Enter the elements of the array"<<endl; for(int i=0;i<10;i++) { cout<<"Enter number for cell "<<i<<endl; cin>>number[i]; } cout<<endl<<"Thank You ! The data entry is over"<<endl; cout<<"Press any key to continue"; getch(); clrscr(); // sorting of data for(int j=0;j<9;j++) { for(int k=j+1;k<10;k++) { if (number[j]>number[k]) { a=number[j]; number[j]=number[k]; number[k]=a; } } } cout<<"The list in ascending order is "; cout<<endl; for(i=0;i<10;i++) cout<<number[i]<<"\t"; cout<<endl<<"Press any key to return to the editor"; getch(); return 0; }

[Link] AM [Link]

// Program to input any string and print the number of 'the'. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> main() { clrscr(); char name[50]; int l=0,c=0; cout<<"Enter any string "<<endl; gets(name); l = strlen(name); cout<<endl; for(int i=0;i<=l;i++) { if ((name[i]=='t') && (name[i+1]=='h') && ((name[i+2])=='e')) c=c+1;} cout<<endl; cout<<"total the is "<<c; getch(); return 0; }

[Link] AM [Link]

// Program to input a string and a character. Print the frequency of // the character within the string. #include<iostream.h> #include<conio.h> #include<string.h> #include<process.h> #include<stdio.h> main() { clrscr(); char name[40],input; int l=0,count=0; cout<<"Enter any word "<<endl; gets(name); cout<<endl<<"Enter the character to print the frequency"; cin>>input; l = strlen(name); cout<<endl; for (int a=0;a<l;a++) { if (name[a]==input) count = count + 1; } cout<<endl<<"The frequency of "<<input<<" is "<<count<<endl; getch(); return 0; }

[Link] AM [Link]

// Program to sort the given strings in Ascending order. #include <stdio.h> #include <conio.h> #include <string.h> void main() { clrscr(); char name[10][20],temp[10][20]; int i,j,n; printf ("\nENTER THE NUMBER OF NAMES TO BE ASCENDED : "); scanf ("%d",&n); for (i=0;i<n;i++) { printf ("ENTER THE %d NAME : ",i+1); scanf ("%s",name[i]); } printf ("\n The ascending order of the names is : \n "); for (i=0;i<n;i++) { for (j=i+1;j<n;j++) { if (strcmp(name[i],name[j])>0) { strcpy (temp[i],name[i]); strcpy (name[i],name[j]); strcpy (name[j],temp[i]); } } printf ("\n%s",name[i]); } getch(); }

[Link] AM [Link]

// Program to define a function and incorporate the array // of structures to input and store any 30 records // with following information of name and marks. // Display the following using functions incorporated through // structure definition viz. display of all entered records, // sort the records according to the marks in descending order // and display of sorted records. #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> struct ward { char name[20]; float marks; } stud[5]; void display(); void sort(); void dispsort(); main() { clrscr(); // Data entry clrscr(); cout<<"D A T A : ENTRY PROCESS: Enter 5 Records Initially"<<endl; for(int i=0;i<5;i++) { cout<<"\nEnter name"; cin>>stud[i].name; cout<<"\nEnter marks"; cin>>stud[i].marks; } clrscr(); display(); // Call of Function // to display data entered. cout<<"Press any key to continue"; getch(); clrscr(); sort(); // Call of Function // to sort data clrscr(); cout<<"Press any key to display "; cout<<"the sorted data"; getch(); dispsort(); // Call of Function // to display the sorted data. cout<<endl; cout<<"Press any key to continue"; getch(); return 0; } void display() // Definition of the function

[Link] AM [Link]

// to display the data values. { clrscr(); cout<<"DATA LIST AS ENTERED"; cout<<endl; for(int k=0;k<5;k++) { cout<<"NAME OF THE STUDENT IS "; cout<<stud[k].name; cout<<endl; cout<<"HIS MARKS IS "; cout<<stud[k].marks; cout<<endl; cout<<"***************************************"; cout<<endl; cout<<"***************************************"; cout<<endl; } } void sort() // Definition of the sort function. { // sorting done according to marks. char nam[20]; int mark=0; for(int r=0;r<4;r++) { for(int s=r+1;s<5;s++) { if (stud[r].marks < stud[s].marks) { strcpy(nam,stud[r].name); strcpy(stud[r].name,stud[s].name); strcpy(stud[s].name,nam); mark=stud[r].marks; stud[r].marks=stud[s].marks; stud[s].marks=mark; } } } } void dispsort() // Definition of the function // to print the sorted data. { clrscr(); cout<<"Display of sorted data according to marks"; cout<<endl; display(); cout<<endl; cout<<"End of data encountered"; cout<<endl; cout<<"Press any key to continue"; getch(); }

[Link] AM [Link]

You might also like