Saturday, December 08, 2012

Calender


#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
typedef int Bool;

// converts 0 to 'S', 1 to 'M', 2 for 'T',3 for 'W',4 for 'T',5 for 'F' ,6 for 'S'
char whatDay (int);

// not very good check for leap years
Bool isLeapYear (int);

// takes the number of the month, a flag saying whether year is leap
int numOfDaysInMonth (int,Bool);

void printHeader (int);

// takes the number of the month, and the first day, prints, and updates
// the first day of the next month
void printMonth (int, int&);

// prints the specified amount of spaces
void skip (int);

// prints leading spaces in monthly calendar
void skipToDay (int);

// terminates program in case of unrecoverable errors
void disaster ();

int main () {

  int year, firstDayInCurrentMonth;
  Bool leap;
  int currentMonth = 1; // start at Jan
  int numDays;

  cout << "What year do you want a calendar for? ";
  cin >> year;
  cout << "What day of the week does January 1 fall on?" << endl;
  cout << "Enter 0 for Sunday, 1 for Monday,2 for Tuesday,3 for Wednesday,4 for Thursday,5 for Friday ,6 for Saturday ";
  cin >> firstDayInCurrentMonth;

  leap = isLeapYear(year);
  skip(9); cout << year << endl;

  while (currentMonth <= 12) {
    numDays = numOfDaysInMonth(currentMonth,leap);
    printHeader(currentMonth);
    printMonth(numDays, firstDayInCurrentMonth);
    cout << endl << endl << endl;
    currentMonth = currentMonth + 1;
  }
  cout << endl;
}

void disaster () {
  cout << "Disaster! Exiting ..." << endl;
  exit (-1);
}

void skip (int i) {
  while (i > 0) {
    cout << " ";
    i = i - 1;
  }
}

char whatDay (int d) {
  if (d == 0) return('S');
  else if (d == 1) return('M');
  else if (d == 2) return('T');
  else if (d == 3) return('W');
  else if (d == 4) return('T');
  else if (d == 5) return('F');
  else if (d == 6) return('S');
  else disaster();
}

Bool isLeapYear (int y) {
  return ((y % 4) == 0); // simplified
}

void printHeader (int m) {

  if (m == 1) { skip(7); cout << "January" << endl; }
  else if (m == 2) { skip(7); cout << "February" << endl; }
  else if (m == 3) { skip(7); cout << "March" << endl; }
  else if (m == 4) { skip(7); cout << "April" << endl; }
  else if (m == 5) { skip(7); cout << "May" << endl; }
  else if (m == 6) { skip(7); cout << "June" << endl; }
  else if (m == 7) { skip(7); cout << "July" << endl; }
  else if (m == 8) { skip(7); cout << "August" << endl; }
  else if (m == 9) { skip(7); cout << "September" << endl; }
  else if (m == 10) { skip(7); cout << "October" << endl; }
  else if (m == 11) { skip(7); cout << "November" << endl; }
  else if (m == 12) { skip(7); cout << "December" << endl; }
  else disaster();

  cout << " S  M  T  W  T  F  S" << endl;
  cout << "____________________" << endl;
}

int numOfDaysInMonth (int m, Bool leap) {
  if (m == 1) return(31);
  else if (m == 2) if (leap) return(29); else return(28);
  else if (m == 3) return(31);
  else if (m == 4) return(30);
  else if (m == 5) return(31);
  else if (m == 6) return(30);
  else if (m == 7) return(31);
  else if (m == 8) return(31);
  else if (m == 9) return(30);
  else if (m == 10) return(31);
  else if (m == 11) return(30);
  else if (m == 12) return(31);
  else disaster();
}

void skipToDay (int d) {
  skip(3*d);
}

void printMonth (int numDays, int& weekDay) {
  int day = 1;

  skipToDay(weekDay);
  while (day <= numDays) {
    cout << setw(2) << day << " ";
    if (weekDay == 6) {
      cout << endl;
      weekDay = 0;
    }
    else weekDay = weekDay + 1;
    day = day + 1;
  }
}

Tuesday, December 04, 2012

GPA calculate in C++


// it is use in kust i calculate my gpa that is correct
#include <iostream>
using namespace std;

int main(){
    float nmbr, grade, credits, GPA = 0, totalCredits = 0;

    cout << "Enter The Number of Courses: ";
    cin >> nmbr;

    for(int i = 0; i < nmbr; i++){
        cout << "Enter the credit number for course No. " << i+1 << " : ";
        cin >> credits;
        totalCredits =totalCredits + credits;

        cout << "Enter the grade for course No. " << i+1 << " : ";
        cin >> grade;
         GPA =GPA+grade*credits;
    }

    GPA /= totalCredits;

    cout << "The GPA Is: " << GPA << " / ";
    if(GPA >=.7 && GPA <= 1)
        cout << "F oh no";
    else if(GPA >= 1 && GPA <= 1.33)
        cout << "D";
    else if(GPA >= 1.33 && GPA <= 1.7)
        cout << "D+";
    else if(GPA >=1.7 && GPA <= 2)
        cout << "C-";
    else if(GPA >= 2 && GPA <= 2.33)
        cout << "C";
    else if(GPA >= 2.33 && GPA <= 2.63)
        cout << "C+";
    else if(GPA >= 2.63  && GPA <= 3)
        cout << "B-";
    else if(GPA >= 3 && GPA <= 3.33)
        cout << "B";
    else if(GPA >=3.33 && GPA <= 3.63)
        cout << "B+";
    else if(GPA >=3.63 && GPA <= 4)
        cout << "A-";
    else if(GPA == 4)
        cout << "A oh....................\n";
 

    return 0;
}

Monday, December 03, 2012

program to find nCr using function in C++


#include<iostream>
 using namespace std;
long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);

main()
{
   int n, r;
   long ncr, npr;

   cout<<"Enter the value of n and r\n";
  cin>>n>>r;

   ncr = find_ncr(n, r);
   npr = find_npr(n, r);

   cout<<n<<"C"<<r<<"=\n"<<ncr;
   cout<<"\n"<<n<<"P"<<r<<" =\n"<<npr;

   return 0;
}

long find_ncr(int n, int r)
{
   long result;

   result = factorial(n)/(factorial(r)*factorial(n-r));

   return result;
}

long find_npr(int n, int r)
{
   long result;

   result = factorial(n)/factorial(n-r);

   return result;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
      result = result*c;

   return ( result );
}

H.C.F and L.C.M in C++


#include <iostream>
 using namespace std;
int main() {
  int a, b, x, y, t, gcd, lcm;

  cout<<"Enter two integers\n";
  cin>>x>>y;

  a = x;
  b = y;

  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }

  gcd = a;
  lcm = (x*y)/gcd;

  cout<<"Greatest common divisor of "<<x<<" and "<<y<<"=\n"<<gcd;
  cout<<"\nLeast common multiple of"<<x<<" and"<<y<<" =\n"<<lcm;

  return 0;
}

Sunday, December 02, 2012

diamond in C++


#include <iostream>
using namespace std;
int main () {
  int width, horizPos, vertPos, beginHoriz, endHoriz;
  char c;
 
  cout << "Enter a character: ";
  cin >> c;
  cout << "Enter an integer: ";
  cin >> width;

  if ((width % 2) == 0) width = width+1;

  horizPos = 0;
  beginHoriz = width / 2;
  endHoriz = beginHoriz;
  while (beginHoriz >= 0) {
    while (horizPos < width) {
      if (horizPos < beginHoriz) cout << " ";
      else if (horizPos <= endHoriz) cout << c;
      else cout << " ";
      horizPos = horizPos + 1;
    }
    cout << endl;
    horizPos = 0;
    beginHoriz = beginHoriz - 1;
    endHoriz = endHoriz + 1;
  }

  horizPos = 0;
  beginHoriz = 1;
  endHoriz = width - 2;
  while (beginHoriz <= width / 2) {
    while (horizPos < width) {
      if (horizPos < beginHoriz) cout << " ";
      else if (horizPos <= endHoriz) cout << c;
      else cout << " ";
      horizPos = horizPos + 1;
    }
    cout << endl;
    horizPos = 0;
    beginHoriz = beginHoriz + 1;
    endHoriz = endHoriz - 1;
  }

}

Structure of a program


Structure of a program
 Probably the best way to start learning a programming language is by writing a program. Therefore, here is our first program:

// my first program in C++
#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}
Hello World!
The first panel (in light blue) shows the source code for our first program. The second one (in light gray) shows the result of the program once compiled and executed. To the left, the grey numbers represent the line numbers - these are not part of the program, and are shown here merely for informational purposes.

The way to edit and compile a program depends on the compiler you are using. Depending on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual or help included with your compiler if you have doubts on how to compile a C++ console program.

The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written:

// my first program in C++ This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is.
#include <iostream> Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.
using namespace std; All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library, and in fact it will be included in most of the source codes included in these tutorials.
 int main () This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function.

The word main is followed in the code by a pair of parentheses (()). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them.

Right after these parentheses we can find the body of the main function enclosed in braces ({}). What is contained within these braces is what the function does when it is executed.
 cout << "Hello World!"; This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program.

cout is the name of the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello World sequence of characters) into the standard output stream (cout, which usually corresponds to the screen).

cout is declared in the iostream standard file within the std namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code.

Notice that the statement ends with a semicolon character (;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).
 return 0; The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code with a value of zero). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.

You may have noticed that not all the lines of this program perform actions when the code is executed. There were lines containing only comments (those beginning by //). There were lines with directives for the compiler's preprocessor (those beginning by #). Then there were lines that began the declaration of a function (in this case, the main function) and, finally lines with statements (like the insertion into cout), which were all included within the block delimited by the braces ({}) of the main function.

REVERSE NUMBER PROGRAM in C++


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

int main()
 {
 int num;

 int rev=0;
 int mod;
 cout<<"Enter Number= ";
 cin>>num;
 do
 {
 mod=num%10;
 rev=(rev*10)+mod;
 num=num/10;
 }
 while(num>=1);
 cout<<"Reverse Is= "<<rev;
 getch();
 }

A-Z in C++


#include<iostream.h>
 #include<conio.h>
 int main()
 {
 char ch='A';
 for(ch='A';ch<='Z';ch++)

 cout<<ch<<",";
 getch();
 }

Time advance program in C++


#include<iostream.h>
#include<conio.h>
class timex {
public:
int hours;
int min;
int seconds;
timex(int h,int m,int s)
{
hours=h;
min=m;
seconds=s;
}
void access(){
 cout<<"hours : "<<hours;
 cout<<"  minutes : "<<min;
 cout<<"  seconds : "<<seconds;
}
void advance(int w,int r,int m){   int a,b,c,e;
cout<<endl<<"enter your hour advance:"; cin>>a;
cout<<endl<<"enter your minutes advance:";  cin>>b;
cout<<endl<<"enter your seconds advance:"; cin>>c;
hours=hours+a;   min=min+b;  seconds=seconds+c;
if(hours>12)
{
            hours=hours%12;

}
if(min>=60)
{   e=min/60;  min=min%60;  hours=hours+e;

}
if(seconds>=60)
{  e=seconds/60;
               min=min+e;
seconds=seconds%60;} }
};
int main()
{        
timex s(12,34,23);                        
 int z,x,v;
s.access();
s.advance(z,x,v);
s.access();
getch();
}

Bill calculation in C++


#include<iostream>


using namespace std;
class customer {
int a;
public:
int e,u,b,d,n;


void domestic(){
if(u<=100){
b=5*u; } if(u>100&&u<=300) {
b=8*u+100;}
if(u>100&&u<=300) {
b=10*u+230;}
} void date(){
if(d>=10){
b=b+200; } }
void showbill(){
cout<<"\nCustomer number: "<<n;
cout<<"\n Numbers of unit consumed: "<<u;
cout<<"\n Today date: "<<d;
cout<<"\nYour bill is Rs: "<<b;
}void commercial(){
b=u*15;
} void info() {
cout<<"\nEnter your customer number: ";  cin>>n;
cout<<"\nEnter your numbers of unit consumed: ";  cin>>u;
cout<<"\nEnter  today date: ";  cin>>d;  }
};
int main(){int e;
cout<<"Enter 1 for domestic user,2 for commercial user: ";
cin>>e;
customer s;
switch(e)
{ case 1:
cout<<" you are domestic user";
break;
case 2:
cout<<"you are commercial user";
break;
default:
cout<<"you entered a invaild choice";

return 0; }
s.info();
if(e==1){
s.domestic();
}
if(e==2){
s.commercial();
}
s.date();
s.showbill();

}

Program shows your star in C++


#include<iostream.h>
#include<conio.h>
int main()
{
    int month;

    cout<<"\nEnter Date: ";
    cin>>date;
    cout<<"\nEnter Month: ";
    cin>>month;
    cout<<"\n\n";

    if(month<=1 && date>=20)
        cout<<"Aquarius";
    else if(month<=2 && date<=18)
        cout<<"Aquarius";
    else if(month<=2 && date>=19)
        cout<<"Pices";
    else if(month<=3 && date<=20)
        cout<<"Pices";
    else if(month<=3 && date>=21)
        cout<<"Aries";
    else if(month<=4 && date<=19)
        cout<<"Aries";
    else if(month<=4 && date>=20)
        cout<<"Taurus";
    else if(month<=5 && date<=20)
        cout<<"Taurus";
    else if(month<=5 && date>=21)
        cout<<"Gemini";
    else if(month<=6 && date<=20)
        cout<<"Gemini";
    else if(month<=6 && date>=21)
        cout<<"Cancer";
    else if(month<=7 && date<=22)
        cout<<"Cancer";
    else if(month<=7 && date>=23)
        cout<<"Leo";
    else if(month<=8 && date<=22)
        cout<<"Leo";
    else if(month<=8 && date>=23)
        cout<<"Virgo";
    else if(month<=9 && date<=22)
        cout<<"Virgo";
    else if(month<=9 && date>=23)
        cout<<"Libra";
    else if(month<=10 && date<=22)
        cout<<"Libra";
    else if(month<=10 && date>=23)
        cout<<"Scorpio";
    else if(month<=11 && date<=21)
        cout<<"Scorpio";
    else if(month<=11 && date>=22)
        cout<<"Sagittarius";
    else if(month<=12 && date<=21)
        cout<<"Sagittarius";
    else if(month<=12 && date>=22)
        cout<<"Capricon";
    else if(month<=1 && date<=19)
        cout<<"Capricon";
    else
        cout<<"Invalid Month:";

    getch();
}

Atm machine program picture in c++


ATM machine in C++


#include  <iostream>
#include  <conio.h>
#include <stdlib.h>
using namespace std;
class Customer {    
   char name[20];
     int p,q;
    char city[20];  
   char v[10];
  int n;
  public:  
  Customer(int a) { p=a;        
        }    
  int getdata() {  
cout << "\nEnter your name: ";  
cin >> name;  
cout << "\nEnter your city: "; cin >> city;          
 cout << "\nEnter current account balance: "; cin >> p;
 cout << "\nEnter account type:"; cin>>v;
 cout << "\n Set your password: "; cin>>q;   }
  int deposit() {         int dep;    
 cout << "\nEnter amount to be deposited: ";  
cin >> dep;         p=p + dep;      }  
 int withdraw() {         int wdraw;    
  cout << "\nEnter amount to be withdrawn: ";
cin >> wdraw;         p=p - wdraw;      }  
int showdata() {    int n; cout << "\nEnter pasword: ";            cin >> n;   if (n==10)
{ cout<<"Name:Asim wadood";
cout<<"\nAccount Balance: Rs."<<p;
cout<<"\nAccount type: current";
cout << "\nCity: " <<"kohat";}
if (n==11)
{cout<<"name:ayaz haider";
cout<<"\nAccount Balance: Rs."<<p;
cout<<"\nAccount type: current";
cout << "\nCity: " << "kohat";}
if (n==12)
{ cout<<"name:Abid shah";
cout<<"\nAccount Balance: Rs."<<p;
cout<<"\nAccount type: fixed";
cout << "\nCity: " << "kohat";}
if (n==13)
{ cout<<"name:Abdul hameed";
cout<<"\nAccount Balance: Rs."<<p;
cout<<"\nAccount type: current";
cout << "\nCity: " << "kohat";}
if (n==q)
{cout << "\nEnter your name: "<<name;  
cout << "\nEnter your city: "<<city;          
 cout << "\nEnter current account balance: "<<p;
 cout << "\nEnter account type:"<<v;
   }
         
 }
  }; int main() {    char choice;   int z = 0;
     
 Customer cust(1000);    while (z == 0) {
          cout<<"\n*********WELCOME TO ASIM BANK ACCOUNT SYSTEM***********\n\n";
  cout << "\n\t" << "Main Menu";    
 cout << "\n\t" << "Select by letter:";
 cout << "\n\t" << "a - Add a customer.";    
 cout << "\n\t" << "d - Deposit money.";    
 cout << "\n\t" << "w - Withdraw money.";  
cout << "\n\t" << "s - Show Account Information.";    
cout << "\n\t" << "q - Quit Application.\n\n";  
cout  << "Choice: ";  
choice = getch();      switch(choice) {         case 'a':        
         system("cls");      int n;            
cust.getdata();      
system("cls");        
break;    
case 'd':  
 system("cls");    
cout << "\nEnter password: ";      
cin >> n;            cust.deposit();  
system("cls");            break;          case 'w':  
system("cls");      
cout << "\nEnter password: ";        
cin >> n;            cust.withdraw();      
system("cls");            break;        
case 's':          
     system("cls");
cust.showdata();      
   getch();            system("cls");    
break;          case 'q':      
                    z = 1;            break;    
 default:          
 cout << "\nInvalid selection. Press a key to return to main menu.";    
 getch();      }  
   if (z == 1)
 {         break;  
 }    }
return 0;}
Add caption

Sunday, November 18, 2012

Show which numbers is greater amongst 3 in C++

#include <conio.h>
#include <iostream.h>
int main()
{
        int a,b,c;
        cout<<"enter a value of a";
        cin>>a;
         cout<<"enter a value of b";
        cin>>b;
         cout<<"enter a value of c";
        cin>>c;
        if (a>b && a>c)
        cout<<"The value A is Greater than all 2";
        else if (b>c)
        cout<<"The value B is Greater than all 2";
        else
        cout<<"The value C is Greater than all 2";
getch();
return 0;
}

Convert decimal numbers to octal numbers in C++

#include<iostream.h>
#include<conio.h>
int main ()
{
    int num,i=0;
    cout<<"Enter the decimal number:";
    cin>> num;
    while(num>0)
    {
                i=num%8;
                num=num/8;  cout<<i;
                }
                cout<<"(Result in reverse order)";
                getch ();
                return 0;
}

conver decimal to Hexadecimal in C++

#include<iostream.h>
#include<conio.h>
int main ()
{
    int num,i=0;
    cout<<"Enter the decimal number:";
    cin>> num;
    while(num>0)
    {
                i=num%16;
                num=num/16;  cout<<i;
                }
               cout<<"(Result in reverse order)";
                getch ();
                return 0;
}

Convert Decimal number to binary numbers in C++

#include<iostream.h>
#include<conio.h>
int main ()
{
    int num,i=0;
    cout<<"Enter the decimal number:";
    cin>> num;
    while(num>0)
    {
                i=num%2;
                num=num/2;  cout<<i;
                }
                cout<<"(Result in reverse order)";
                getch ();
                return 0;
}

Tuesday, November 13, 2012

Displaying even numbers upto 100 in C++

#include <iostream.h>
#include <conio.h>
int main()
{
          int i;
for(int i=1;i <= 100 ;i++)
{ if(i%2==0)
cout<<i<<endl;
}
getch();
return 0;
}

Build a diamond in C++

#include <string.h>
 #include <iostream.h>
 #include <conio.h>
int main()
{
    int i, j, k;
    int n = 0;

    cout<<"Program for displaying pattern of *.\n";
    cout<<"Enter the maximum number of *: ";
    cin>>n;

  cout<<"\nHere is the Diamond of Stars\n";

    for (i = 1; i <= n; i++)
    {
          for (j = 0; j < (n - i); j++)
                cout<<" ";
          for (j = 1; j <= i; j++)
                cout<<"*";
          for (k = 1; k < i; k++)
                cout<<"*";
          cout<<"\n";
    }

    for (i = n - 1; i >= 1; i--)
    {
          for (j = 0; j < (n - i); j++)
                cout<<" ";
          for (j = 1; j <= i; j++)
                cout<<"*";
          for (k = 1; k < i; k++)
                cout<<"*";
          cout<<"\n";
    }
   
    cout<<"\n";
    getch();
    return 0;
}

comparing character and integer in C++

#include<iostream.h>
#include<conio.h>
main()
{
      int i;
      char c;
      for(i=0;i<256;i++)
      {
                        c=i;
                        cout<<i<<"\t"<<c<<endl;
                        }
                        getch();
                        return 0;

}

Weather program in C++

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

 #include<windows.h>   
int main()
{
int w;
int a,b;
system("color 5e");


cout<<"   ASIM KHAN BANGASH"<<endl;
cout<<"Enter month numbers between 1 and 12:";
cin>>w;
switch(w)
{
case 1:
case 2:
case 11:
case 12:
cout<<"The weather is winter";
break;
case 9:
case 10:
cout<<"The weather is Autum";
break;
case 3:
case 4:
cout<<"The weather is Spring";
break;
case 5:
case 6:
case 7:
case 8:
cout<<"The weather is Summer";
break;
defualt:
cout<<"You entered an Invalid month";
}
getch();
return 0;
}
   

Table in C++

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

using namespace std;
int main()
{
int i=1;
int n,r;
int v;
cout<<"Enter a table number you want:";
cin>>n;
cout<<"Enter the Table Limit:";
cin>>v;
while(i<=v)
{
r=n*i;
cout<<n<<"*"<<i<<"="<<r<<endl;
i++;
}
getch();
    return 0;
}

Quadratic equation in C++

#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{
        int a,b,c,d,e,i;
        cout<<"Solving the quadratic equation ax^2+bx+c=0"<<endl;
        cout<<"Enter 'a' value:";
        cin>>a;
        cout<<"Enter 'b' value:";
        cin>>b;
        cout<<"Enter 'c' value:";
        cin>>c;
        i=1/2;
        d=(b*b)+4*(a*c);
        e=sqrt(d)/2*a;
        cout<<endl<<"The values of x are"<<-b+e<<" and "<<-b-e;
        getch();
        return 0;
}

power function in C++

#include<iostream.h>
#include<conio.h>
int power(int,int);
int main()
{
int base,pow,ans;
cout<<"Enter base:";
cin>>base;
cout<<"Enter power:";
cin>>pow;
ans=power(base,pow);
cout<<"The answer is:"<<ans;
getch();
return 0;
}
int power(int b,int p)
{
int rp=1;
for(int i=1;i<=p;i++)
rp=rp*b;
return rp;
}

Log program in C++

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
          int a;
          float r;
          cout<<"Enter a number :";
          cin>>a;
          r=log(a);
        
          cout<<"the log of  "<<a<<"  is :"<<r;
          getch();
          return 0;
          }

Factorial in C++

# include <conio.h>
# include <iostream.h>
int main()
{
long rt=1;
int fact;
cout <<"Enter the number for factorial: ";
cin >>fact;
for(int i=1;i<=fact;i++)
{
rt=rt*i;
}
cout<<"the Factorial of "<<fact<<" is: "<<rt;
getch();
return 0;
}

square diagram in C++

#include <string.h>
 #include <iostream.h>
 #include <conio.h>
int main(){
    int u,v, k;
    int n = 0;
    cout<<"Program for displaying pattern of *.\n";
    cout<<"Enter the width of square: ";
    cin>>n;
 cout<<"Enter the length of square: ";
    cin>>v;
  cout<<"\nHere is the square of Stars\n";

    for (int i = 1; i <= n+3; i++)
    { cout<<"*";
    } cout<<endl;
    for (int i = 1; i <= n+3; i++)
    { cout<<"*";
    } cout<<endl;
    for (int i = 1; i <= v; i++)
    { cout<<"**";
        for (int i = 1; i <= n-1; i++)
    { cout<<" ";
}
   
    cout<<"**"<<endl;
    }
    for (int i = 1; i <= n+3; i++)
    { cout<<"*";
    } cout<<endl;
    for (int i = 1; i <= n+3; i++)
    { cout<<"*";
    }
    getch();
    return 0;
}

square root in C++

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main(){    double num, ans;
    cout<<"Enter number to find square root";
    cin>>num;
    ans=sqrt(num);
    cout<<"The square root of "<<num<< "="<<ans;
    getch();
}

first program in C++

#include<iostream.h>
#include <conio.h>
int main()
{
        int a,b,c;
        cout<<"enter a 1st number:";
        cin>>a;
        cout<<"enter 2nd number:";
        cin>>b;
        c=a+b;
        cout<<"The sum of two number is:"<<c;
        getch();
        return 0;
}