Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Name: Jerick Villanueva

Course: 1st Year BSIT

Subject: IT 2 - Computer Programming 1

Instructor: Engr. Ralph Bryell Louie A. Olaso

Module 2

Exercise Set 2.1                                     BOOLEAN OPERATIONS

  a b    c         a&b     b|     c^d ~d&~b ~a | ~c


d c

               0   0    0    0    1    1


0 0 0

               1   0    0    1    1    1


0 0 0

               0   0    1    1    1    0


0 0 1

               1   0    1    0    1    0


0 0 1

               0   0    1    0    0    1


0 1 0

               1   0    1    1    0    1


0 1 0

               0   0    1    1    0    0


0 1 1

               1   0    1    0    0    0


0 1 1

               0   0    0    0    1    1


1 0 0

               1   0    0    1    1    1


1 0 0

               0   0    1    1    1    0


1 0 1
               1   0    1    0    1    0
1 0 1

               0   1    1    0    0    1


1 1 0

               1   1    1    1    0    1


1 1 0

               0   1    1    1    0    0


1 1 1

               1   1    1    0    0    0


1 1 1

Exercise 2.2

Multiple Choice

1. C

2. C

3. B

4. C

5. A

6. B

7. A

8. A

9. A

10. A

11. C

12. A

13. A

14. B

15. A
Exercise 2.3

C++  Basic  Programs

1.) Write a C++ program to print the following lines.

You are 17 years old.

You are not allowed to watch the video.

#include<iostream>

using namespace std;

int main()

cout << "Your are 17 years old!";

cout << "You are not allowed to watch the video!";

2.) Write C++ program to print the asterisk pattern as shown below.

**

***

****

*****

#include <iostream>

using std::cout;

using std::endl;
using std::cin;

int main()

    int n;

    cout<<"Enters 5 numbers between 1 and 10: ";

    for(int i=1;i<=5; ++i){

        cin >> n;

        for(int x=1;x<=n; ++x){

            cout<<"*";

        }

        cout<<"\n";

    }

    cout<<endl;

    return 0;

    

3.) Write a C++ program to declare 3 integers and 2 float variables. Assign 12, 22, 34, 35.6 and 88.1,
respectively

4.) Write a C++ program that will add and subtract declared integer and float variables. Assign 24, 15,
32.4 and 45.

A. 24 will be added to 15

#include<iostream>

using namespace std;

int addition (int a, int b)


{

    int r;

    r=a+b;

    return (r);

int main()

    int z;

    z = addition (24 , 15);

    cout<<" the result is " <<z;

    return 0;

the result is 39

B. 15 will be added 32.4

#include<iostream>

using namespace std;

int addition (int a, int b)

    int r;

    r=a+b;

    return (r);

int main()

{
    int z;

    z = addition (15 , 32);

    cout<<" the result is " <<z;

    return 0;

the result is 47

C. 45 will be subtracted to 15

#include<iostream>

using namespace std;

int subtraction (int a, int b)

    int r;

    r=a-b;

    return (r);

int main()

    int z;

    z = subtraction (45 , 15);

    cout<<" the result is " <<z;

    return 0;

}
the result is 30

D. 32.4 will be subtracted to 24

#include<iostream>

using namespace std;

int subtraction (int a, int b)

    int r;

    r=a-b;

    return (r);

int main()

    int z;

    z = subtraction (32 , 24);

    cout<<" the result is " <<z;

    return 0;

the result is 8

Module 3

Exercise

1. Print "Hello World" if x is greater than y


#include <iostream>

using namespace std;

int main(){

    int x=50;

    int y(10);

    if (x>y){

        cout <<"hello world";

    }

2. Use a for loop to print "Yes" 5 times:

#include <iostream>

using namespace std;

int main(){

    for (int i = 0; i < 5; i++){

        cout <<"Yes" << "\n";

    }

}
Module 4

Exercise

1. Insert the missing parts to complete the following switch statement.

int day = 2;

switch (x) {

  

Case 1:

    System.out.println("Saturday");

    break;

  Case 2:

    System.out.println("Sunday");

    Break ;

2. Stop the loop if i is 5:

for (int i = 0; i < 10; i++) {


if (i == 5) { 

Break ;

 }

 cout << i << "\n";


}

Module 5

Exercise
1. Create a function named myFunction and call it inside main().

#include <iostream>

using namespace std;

void myFunction(){

    cout << "I just got execute";

int main(){

    myFunction();

    return 0;

You might also like