loading...
مرجع مهندسی نرم افزار
آخرین ارسال های انجمن
حامد شیرزاد بازدید : 625 شنبه 28 آبان 1390 نظرات (0)
Calculator - A division, multiplication, adding, subtracting program.
 
#include<iostream>
#include<string>
using namespace std;
float mult(float num1,float num2);
float add(float num1,float num2);
float sub(float num1,float num2);
float divide(float num2,float num2);
int main()
{
    int choice;
    float num1,num2;
 
 
    cout<<" CALCULATOR "<<endl;
 
 
    cout<<"    Make a selction:"<<endl;
    cout<<"    1.Division"<<endl;
    cout<<"    2.Adding"<<endl;
    cout<<"    3.Subtraction"<<endl;
    cout<<"    4.multiplication"<<endl;
    cout<<"
YOUR CHIOCE IS: ";
    cin>>choice;
    switch(choice){
                   case 1:
                        cout<<"Please enter the two numbers you want to
divide, divisor first!: ";
                        cin>>num1>> num2;
                        cin.ignore();
 
cout<<"
"<<num1<<"/"<<num2<<"="<<divide(num1,num2)<<endl;
                        break;
                              case 2:
                                   cout<<"Please enter the two numbers 
you
want to add: ";
                                   cin>>num1>> num2;
                                   cin.ignore();
 
cout<<"
"<<num1<<"+"<<num2<<"="<<add(num1,num2)<<endl;
                                    break;
                                           case 3:
                                                 cout<<"Please enter 
the
two numbers you want to subtract, The number you want to subtract from
first!: ";
                                                 cin>>num1>> num2;
                                                 cin.ignore();
 
cout<<"
"<<num1<<"-"<<num2<<"="<<sub(num1,num2)<<endl;
                                                 break;
                                                       case 4:
                                                             
cout<<"Please
enter the two numbers you want to multiply: ";
                                                             
cin>>num1>>
num2;
                                                             
cin.ignore();
 
cout<<"
"<<num1<<"*"<<num2<<"="<<mult(num1,num2)<<endl;
                                                              break;
 
default:
 
cout<<"Invalid Entry!, BYE!!!"<<endl;
 
cin.ignore();
 
break;
                                                                          
        }
                                cin.ignore();
                                return 0;
}
float mult(float num1,float num2){
    return (num1*num2);
}
float add(float num1,float num2){
    return (num1+num2);
}
float sub(float num1,float num2){
    return (num1-num2);
}
float divide(float num1,float num2){
    return (num1/num2);
}
حامد شیرزاد بازدید : 1227 شنبه 28 آبان 1390 نظرات (0)
Program to find your Day of Birth given Date of Birth
 
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
 
main()
{
 clrscr();
 int d,m,y,year,month,day,i,n;
 printf("Enter how many times you want to run this program : ");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
 printf("
 
Enter the date :    ");
 scanf("%d%d%d",&d,&m,&y);
 if( d>31 || m>12 || (y<1900 || y>=2000) )
  {
   printf("
 
INVALID INPUT
");
   getch();
   exit(0);
  }
 year = y-1900;
 year = year/4;
 year = year+y-1900;
 switch(m)
  {
   case 1:
   case 10:
            month = 1;
            break;
   case 2:
   case 3:
   case 11:
            month = 4;
            break;
   case 7:
   case 4:
           month = 0;
           break;
   case 5:
           month = 2;
           break;
   case 6:
           month = 5;
           break;
   case 8:
           month = 3;
           break;
   case 9:
   case 12:
           month = 6;
           break;
  }
 year = year+month;
 year = year+d;
 day  = year%7;
 switch(day)
  {
   case 0:
           printf("
 
Day is SATURDAY
");
           break;
   case 1:
           printf("
 
Day is SUNDAY
");
           break;
   case 2:
           printf("
 
Day is MONDAY
");
           break;
   case 3:
           printf("
 
Day is TUESDAY
");
           break;
   case 4:
           printf("
 
Day is WEDNESDAY
");
           break;
   case 5:
           printf("
 
Day is THURSDAY
");
           break;
   case 6:
           printf("
 
Day is FRIDAY
");
           break;
  }
}
 getch();
 return 0;
}
حامد شیرزاد بازدید : 1590 شنبه 28 آبان 1390 نظرات (0)
Absolute Value Calculation
This is a simple function that calculates the absolute value of a number:
 
#include <;iostream>
using namespace std;
double Abs(double Nbr)
{
//    return (Nbr >;= 0) ? Nbr : -Nbr;
    if( Nbr >;= 0 )
        return Nbr;
    else
        return -Nbr;
}
 
int main()
{
    double Number = -88;
    double Nbr    = Abs(Number);
 
    cout <;< "The absolute value of " << Number << " is " << Nbr << endl;
 
    return 0;
}
 
Here is an example of running the program:
 
The absolute value of -88 is 88
حامد شیرزاد بازدید : 455 شنبه 28 آبان 1390 نظرات (0)
A simple example using a virtual function.
#include <;iostream>
using namespace std;
class BaseClass {
public:
  int i;
  BaseClass(int x) { 
     i = x; 
  }
  virtual void myFunction()
  {
    cout <;< "Using BaseClass version of myFunction(): ";
    cout <;< i << 'n';
  }
};
class DerivedClass1 : public BaseClass {
public:
  DerivedClass1(int x) : BaseClass(x) {}
  void myFunction() 
  {
    cout <;< "Using DerivedClass1's version of myFunction(): ";
    cout <;< i*i << 'n';
  }
};
class DerivedClass2 : public BaseClass {
public:
  DerivedClass2(int x) : BaseClass(x) {}
  void myFunction() 
  {
    cout <;< "Using DerivedClass2's version of myFunction(): ";
    cout <;< i+i << 'n';
  }
};
int main()
{
  BaseClass *p;
  BaseClass ob(10);  
  DerivedClass1 derivedObject1(10);   
  DerivedClass2 derivedObject2(10); 
 
  p = &;ob;
  p->;myFunction();                         // use BaseClass's myFunction()
 
  p = &;derivedObject1;
  p->;myFunction();                         // use DerivedClass1's myFunction()
 
  p = &;derivedObject2;
  p->;myFunction();                         // use DerivedClass2's myFunction()
 
  return 0;
}
حامد شیرزاد بازدید : 468 جمعه 27 آبان 1390 نظرات (0)
An Example of Exception Handling
#include <;iostream>
using namespace std;
int main()
{
    unsigned int TypeOfLoan = 0;
    const char *LoanType[] = { "Personal",
                "Car",
                "Furniture",
                "Musical Instrument",
                "Boat" };
    try {
        cout <;< "Enter the type of loann";
        for(int i = 0; i < 4; i++)
            cout <;< i + 1 << ") " << LoanType[i] << endl;
        cout <;< "Your choice: ";
        cin >;> TypeOfLoan;
 
        if( TypeOfLoan <; 1 || TypeOfLoan > 5 )
            throw "Number out of rangen";
        cout << "nType of Loan: " << LoanType[TypeOfLoan] << endl;
    }
    catch(const char* Msg)
    {
        cout <;< "Error: " << Msg << endl;
    }
    catch(...)
    {
        cout <;< "nSomething went wrongnn";
    }
 
    return 0;
}

تعداد صفحات : 6

درباره ما
به نام آنکه جان را فکرت آموخت در این وبلاگ سعی می شود به صورت تخصصی به مباحث مربوط به مهندسی نرم افزار به خصوص برنامه نویسی کامپیوتری پرداخته شود. مدیر وبلاگ : حامد شیرزاد
اطلاعات کاربری
  • فراموشی رمز عبور؟
  • آمار سایت
  • کل مطالب : 431
  • کل نظرات : 9
  • افراد آنلاین : 2
  • تعداد اعضا : 109
  • آی پی امروز : 33
  • آی پی دیروز : 185
  • بازدید امروز : 929
  • باردید دیروز : 718
  • گوگل امروز : 0
  • گوگل دیروز : 0
  • بازدید هفته : 1,978
  • بازدید ماه : 4,629
  • بازدید سال : 23,730
  • بازدید کلی : 792,258
  • کدهای اختصاصی

    قالب وبلاگ