Sunday, 16 November 2014

C++ Codes

Object Oriented Programming
Assignment # 01

Q1: What is the principle advantage of an un-sized array?
ANS:
            The Advantage of an un-sized array is that we can save number of elements in array by our choice as by defining the array we are restricted to use only the desired size of an array.







Q2: Explain the difference between the prefix and postfix form of increment operator?
ANS:
            The difference between prefix and postfix is that prefix increment operator increment the number first and then print it.
While in case of postfix increment operator it print the number first and then made an increment.






Q3: Write a program that averages the absolute value of first ten values entered by user. Display the result.

ANS:
            Program Code:
#include <iostream>
using namespace std;
int main()
{
int arr[10];
int i,j;
float sum,avg;
sum=0;
for(i=0;i<10;i++)
{
            cout<<"Enter the array's "<<i<<" element: ";
            cin>>arr[i];
            sum=sum+arr[i];
}
avg=sum/10;
cout<<"The Average is "<<avg<<endl;
}





Q4: Write a program that finds all the prime number between 1 to 100. Display the result.
ANS:
            Program Code:
#include <iostream>
using namespace std;
int main ()
{
    for (int i=2; i<100; i++)
        for (int j=2; j<i; j++)
        {
            if (i % j == 0)
                break;
            else if (i == j+1)
                cout <<"Prime Numbers are "<< i <<endl;

        }  
    return 0;
}




Q5: Write a program that…….. ? ?
ANS:
            Program Code:
#include <iostream>
using namespace std;
void main()
{int i,j,k,l;
k=00;
l=00;
for(i=0;i<6;i++)
{
cout<<endl<<"  "<<k;
l=k+1;
k=k+10;
for(j=0;j<5;j++)
{
cout<<"  "<<l;
l=l+1;
}}cout<<endl;}



C++ ProgrAMS

Q1. Write a program that will take input of two numbers from user and will show result of addition, subtraction, multiplication, division and remainder.

Program Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float x,y,z;
      cout<< "Enter a Number: ";
cin>> x;
cout<<"Enter another Number: ";
cin>>y;
z=x+y;
cout<<"Addition is "<<z<<endl;
z=x-y;
cout<<"Subtraction is "<<z<<endl;
z=x*y;
cout<<"Multiplication is "<<z<<endl;
z=x/y;
cout<<"Division is "<<z<<endl;
getche ();
return 0;
}





Q2. Write a program that will take two inputs in Kilogram and Height of a person and program will calculate its BMI (body mass index).Display BMI as output.

Program Code:

#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
      float x,y,z,d;
      cout<<"Enter mass in kg: ";
      cin>>x;
      cout<<"Enter Height in cm: ";
      cin>>y;
      z=y/100;
      d=x/(z*z);
      cout<<"Body Mass Index(BMI) = "<<d;
      getche();

}














Q3. Write a program that will take input cm (centimeter) value from user and program will convert in
            Inches
            Foot
            Meter
            Yard
            Kilometer
            Miles
Display all these values as output.

Program Code:
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{float x,y;
cout<<"Enter a number in cm: ";
cin>>x;
y=x*0.39370;
cout<<"The Number in inches is "<<y<<endl;
y=x * 0.032808;
cout<<"The Number in Foot is "<<y<<endl;
y=x/100;
cout<<"The Number in meters is "<<y<<endl;
y=x * 0.010936;
cout<<"The Number in Yards is "<<y<<endl;
y=x/100000;
cout<<"The Number in Km is "<<y<<endl;
y=x/160000;
cout<<"The Number in Mile is "<<y<<endl;
getche ();
return 0;
}

Q3. Write a program that will take input currency in Dollars and will convert in
            Rupees
            Ponds
            Euro
            Dinar
            Riyal

Display all these as output.

Program Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{float x,y;
cout<<"Enter the currency in DOLLARS: ";
cin>>x;
y=x*102.12;
cout<<"The currency in Rupees is "<<y<<endl;
y=x * 0.62;
cout<<"The currency in Pound is "<<y<<endl;
y=x*0.78;
cout<<"The currency in Euro is "<<y<<endl;
y=x * 1162;
cout<<"The currency in Iraqi Dinar is "<<y<<endl;
y=x*3.75;
cout<<"The currency in Saudi Riyal is "<<y<<endl;
getche ();
return 0;
}



Q6. Write a program that will take your subject marks and will calculate your CGPA.
       For this purpose you need to search formula that will help you to calculate CGPA.

Program Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{float x,y,z;
float cal,ap,wp,lca,isl,cf,bme,edc,ems,la,ode,cad;
cout<<"Enter the grade in Calculus ";
cin>>cal;
cout<<"Enter the grade in Applied Physics ";
cin>>ap;
cout<<"Enter the grade in Workshop ";
cin>>wp;
cout<<"Enter the grade in LCA ";
cin>>lca;
cout<<"Enter the grade in Islamiat ";
cin>>isl;
cout<<"Enter the grade in Computer Fundamentals ";
cin>>cf;
cout<<"Enter the grade in BME ";
cin>>bme;
cout<<"Enter the grade in EDC ";
cin>>edc;
cout<<"Enter the grade in EMS ";
cin>>ems;
cout<<"Enter the grade in LA ";
cin>>la;
cout<<"Enter the grade in ODE ";
cin>>ode;
cout<<"Enter the grade in CAD ";
cin>>cad;
y=(cf*3+isl*2+wp*2+ap*4+cal*3+lca*4)/18;
cout<<"The Spga in 1st Semester is "<<y<<endl;
z=(bme*3+edc*4+ems*4+ode*3+la*3+cad*1)/18;
cout<<"The Spga in 2nd Semester is "<<z<<endl;
x=(y+z)/2;
cout<<"The Cgpa is "<<x<<endl;
      getche ();
      return 0;
}






Program for Calculator of arithmatic operation:

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{char operation;
int a,b;
      cout<<"Enter first Number: ";
      cin>>a;
      cout<<"Enter second Number: ";
      cin>>b;
      cout<<"Enter an operation arithmatic operation do you want: ";
      cin>>operation;
      switch (operation)
      {
      case '+' :
           
            cout<<"The Addition of numbers= "<<a+b;
            break;
      case '-':
      cout<<" The Subtraction of numbers= "<<a-b;
            break;
      case '*':
            cout<<"The Multiplication of numbers= "<<a*b;
            break;
      case '/':
            cout<<"The Division of numbers= "<<a/b<<endl;
            break;
      }
      getche ();
      return 0;
}



Calculator Using If-else Statement:
Program Code;
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{float x,y,z;
int operation;
cout<<"Enter a Number:";
cin>>x;
cout<<"Enter another Number:";
cin>>y;
cout<<"Enter 1 for Addition, 2 for Subtraction"<<endl<<"      3 for Multiplication, 4 for Division ";
cin>>operation;
if (operation ==1)
{cout<<"The Addition is "<<x+y<<endl;}
else
if(operation == 2)
{cout<<"The Subtraction is "<<x-y<<endl;}
else
if(operation == 3)
{cout<<"The Product is "<<x*y<<endl;}
else
{cout<<"The Division is "<<x/y<<endl;}
getche ();
return 0;
}


Bit Wise Operations

Object Oriented Programming
Lab Report
Bit Wise Functions:
Left Shift
            Left Shift makes the number to shift towards left. This sequence is used in Binary Number system and conversion is done in binary number system. Considering an example will help to understand it properly.
e.g.
·         An 8 bit number (10010101) in Base 2.
·         Make 3 left shift of the red number 1
Solution:
            Hence by left shifting it we will get a number
                        (10101000) in Base 2

Right Shift
            Right Shift makes the number to shift towards right. This sequence is used in Binary Number system and conversion is done in binary number system. Considering an example will help to understand it properly.
e.g.
·         An 8 bit number (10010101) in Base 2.
·         Make 3 right shift of the red number 1
Solution:
            Hence by right shifting it we will get a number
                        (00010010) in Base 2
Logical Operators
        I.            AND
      II.            OR
   III.            NOT
    IV.            XOR
Symbols Notation and Operations for Logical Operators:

     I.        AND     &       Multiplication         (A&B)
   II.        OR      |        Addition       (A|B)
 III.        NOT    ~       Inverter        (A~)
  IV.        XOR    ^        A`B +AB`      (A^B)





Binary Options Trading Signals Live!

advertise

Make Money With Google - 7 Day Test Trial!

Powered By Blogger

Total Pageviews

Powered by Blogger.

Translate

Search This Blog

Visitors

Configurar Mikrotik Wireless Como Un Experto (view mobile)

 

© 2013 All in One. All rights resevered. Designed by Templateism

Back To Top