Question:

Please give me a sample of a computer program. Thank you!?

by  |  earlier

0 LIKES UnLike

Please give me a sample of a computer program. Thank you!?

 Tags:

   Report

3 ANSWERS


  1. Python:

    #!/usr/bin/python2.5

    age = 16

    print "hello I'm " + str(age) + " years old"

    C++

    #include <iostream>

    #include <fstream>

    using namespace std;

    int main ()

    {

      string afile = "test.txt";

      cout << afile ;

      std::cout << std::endl;

      ifstream infile;

      //infile.open (afile, ifstream::app  = ifstream::in);

      infile.open(afile);

      while (infile.good())

        cout << (char) infile.get();

      infile.close();

      return 0;

    }

    Fortran:

          PROGRAM NAMES

          CHARACTER *20 NAME(5)

          CHARACTER *20 LASTNAME

          INTEGER COUNTER, INDX

          LOGICAL FOUND

          DATA NAME(1),NAME(2),NAME(3),NAME(4),NAME(5) /

         +'A.B ONE','B.C TWO','C.D THREE','D.E FOUR','E.F FIVE'/

          PRINT *,'ENTER SURNAME....'

          READ *,LASTNAME

          FOUND = .FALSE.

          DO COUNTER = 1,5

                INDX = INDEX(NAME(COUNTER),' ')

                IF (LASTNAME .EQ. (NAME(COUNTER)(INDX+1 : ))) THEN

                    PRINT *,LASTNAME // ' HAS THE INITIALS ' //

         +NAME(COUNTER)(:INDX-1)

                   FOUND = .TRUE.

                END IF

          END DO

          IF (.NOT. FOUND) THEN

               PRINT *,LASTNAME // ' NOT FOUND'

          END IF

          STOP

          END

    Pascal:

    program sortdata(input,output);

    type Ar5 = array[1..5] of real;

    var i: integer;

       X: Ar5;

       Y: Ar5;

       Z: Ar5;

    begin

       writeln('Please enter 5 numbers');

       for i := 1 to 5 do

          read(X[i]);

       writeln('Please enter another 5 numbers');

       for i := 1 to 5 do

          read(Y[i]);

       for i := 1 to 5 do

           Z[i] := sqrt(X[i] + Y[i]);

       writeln('X':7,'Y':7,'Z':7);

       for i := 1 to 5 do

          writeln(X[i]:5:2,'   ',Y[i]:5:2,'   ',Z[i]:5:2);

    end.


  2. include <stdio.h>

    int main(void)

    {

         int n = 16;

         printf("Hi, I am %d years old.\n", n);

         return 0;

    }

  3. this is a C++ prog. hey this is a program that i made and it's really simple :-) just finding some volumes but with a little bit of "switch" tricks hehehe ijust check some of the errors.

    #include <iostream>

    #include <stdio.h>

    #include <math.h>

    #define PI 3.1416

    using namespace std;

    /*This also include some good and understandable command that you can use like using the "switch" and couts and other mathematical operations applied on C++*/

    main()

    {

          float base,height,altitude,side,radius,volume,...

          int choice;

          

          cout << "This is Ezekiel's Surface Area and Volume Finder Program." << endl;

          cout << "Contact me at jackerx_o5@yahoo.com." << endl;

          cout << "If there are some errors" << endl;

          cout << "please report for immediate fixes" << endl;

          cout << endl;

          

          cout << "Enter the object of choice" << endl;

          cout << "1.    Cube" << endl;

          cout << "2.    Parallelpipe" << endl;

          cout << "3.    Cylinder" << endl;

          cout << "4.    Pyramid" << endl;

          cout << "5.    Sphere" << endl;

          cin >> choice;

          

          

          switch (choice)

          {

                 case 1:

                      cout << "Enter a side of the cube:" << endl;

                      cin >> side;

                      

                      volume = side*side*side;

                      sarea = 6*side*side;

                      

                      cout << "The volume is " << volume << " cubic units" << endl;

                      cout << "The total surface area is " << sarea << " square units" << endl;

                 break;

                

                 case 2:

                      cout << "Enter dimensions of the parallelpipe:" << endl;

                      cin >> a;

                      cin >> b;

                      cin >> c;

                      

                      volume = a*b*c;

                      sarea = 2*((a*b)+(b*c)+(a*c));

                      

                      cout << "The volume is " << volume << " cubic units" << endl;

                      cout << "The total surface area is " << sarea << " square units" << endl;

                 break;

                

                 case 3:

                      cout << "Enter the radius of the base:" << endl;

                      cin >> radius;

                      cout << "Enter the height of the cylinder:" << endl;

                      cin >> height;

                      

                      volume = height*(PI*radius*radius);

                      sarea = (PI*radius*radius)+(2*PI*radius*height);

                      

                      cout << "The volume is " << volume << " cubic units" << endl;

                      cout << "The total surface area is " << sarea << " square units" << endl;

                 break;

                

                 case 4:

                      cout << "Enter the base of the Pyramid:" << endl;

                      cout << "1.    Square" << endl;

                      cout << "2.    Circle" << endl;

                      cout << "3.    Rectangle" << endl;

                      cout << "4.    Triangle" << endl;

                      cout << "5.    Others" << endl;

                      cin >> choice;

                      

                      switch (choice)

                      {

                             case 1:

                                  cout << "Enter the side of the square:" << endl;

                                  cin >> side;

                                  cout << "Enter the height of the pyramid:" << endl;

                                  cin >> height;

                                  

                                  volume = (side*side)*height/3;

                                  c = sqrt(2*(side*side/4));

                                  L = sqrt((c*c)+(h*h));

                                  sarea = ((4*side)*(L))/2;

                                  

                                  

                                  cout << "The volume is " << volume << " cubic units" << endl;

                                  cout << "The total surface area is " << sarea << " square units" << endl;

                             break;

                            

                             case 2:

                                  cout << "Enter the radius of the base:" << endl;

                                  cin >> radius;

                                  cout << "Enter the height:" << endl;

                                  cin >> h;

                                  

                                  volume = (PI*radius*radius)*h/3;

                                  L = sqrt((radius*radius)+(h*h));

                                  sarea = L*PI*radius;

                                  

                                  cout << "The volume is " << volume << " cubic units" << endl;

                                  cout << "The total surface area is " << sarea << " square units" << endl;

                             break;

                            

                             case 3:

                                  cout << "Enter the dimensions of the base" << endl;

                      

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.