0% found this document useful (0 votes)
29 views10 pages

Activity 2 (Add)

The document contains 5 activities demonstrating C++ programming concepts. Activity 1 prints "Hello World". Activity 2 demonstrates arithmetic operations like addition, subtraction, multiplication and division on two numbers. Activity 3 allows the user to choose an arithmetic operation and perform calculations. Activity 4 sorts an array of numbers. Activity 5 defines classes to store contact entries in a contact list and print the list.

Uploaded by

Katarina Myoi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

Activity 2 (Add)

The document contains 5 activities demonstrating C++ programming concepts. Activity 1 prints "Hello World". Activity 2 demonstrates arithmetic operations like addition, subtraction, multiplication and division on two numbers. Activity 3 allows the user to choose an arithmetic operation and perform calculations. Activity 4 sorts an array of numbers. Activity 5 defines classes to store contact entries in a contact list and print the list.

Uploaded by

Katarina Myoi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Activity 1:

#include <iostream>

using namespace std;

int main ()

cout << "Hello World" << endl;

return 0;

Activity 2 (add) :

#include <iostream>

using namespace std;

int main ()

int num1 = 5, num2 = 3;

int num3 = num1 + num2;

cout << "This program will perform the addition on two numbers.\nThe sum of " << num1 << "
and " << num2 << " is " << num3 << endl;

}
Activity 2 (sub):
#include <iostream>

using namespace std;

int main ()

int num1 = 5, num2 = 3;

int num3 = num1 - num2;

cout << "This program will perform subtraction on two numbers.\nThe Difference of " << num1
<< " and " << num2 << " is " << num3 << endl;

Activity 2 (mul):

#include <iostream>

using namespace std;

int main ()

int num1 = 5, num2 = 3;

int num3 = num1 * num2;


cout << "This program will perform multiplication on two numbers.\nThe product of " << num1
<< " and " << num2 << " is " << num3 << endl;

Activity 2 (div):
#include <iostream>

using namespace std;

int main ()

int num1 = 5, num2 = 3;

int num3 = num1 / num2;

cout << "This program will perform division of two numbers.\nThe quotient of " << num1 << "
and " << num2 << " is " << num3 << endl;

Activity 3:

#include <iostream>

using namespace std;


int main(){

float num1, num2, num3;

char o, choice;

do{

cout << " [+] Addition\n [-] Subtraction\n [*] Multiplication\n [/] Division\n\n" ;

cout << "\nInput First Number: "; cin >> num1;

cout << "Input Second Number: "; cin >> num2;

cout << "Input an Operator: "; cin >> o;

if(o == '+'){cout << "\nSum: "<< num1 + num2;}

else if(o == '-'){cout << "\nDifference: " << num1 - num2;}

else if(o == '*'){cout << "\nProduct: " <<num1 * num2;}

else if(o =='/'){

if(num2 == 0){cout << "Error";}

else{cout << "\nQuotient: " << num1 / num2;}

else{cout << "Invalid Operator:" << endl;}

cout << "\n\nWant to solve again[y/n]? "; cin >> choice; cout << endl;
}while(tolower(choice)=='y');

Activity 4:
#include <iostream>

using namespace std;

void swap(int &a, int& b){

int temp = a;

a=b; b = temp;

void sort_array(int array[], int size){

cout<<"unsorted\n";

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

cout<<array[i]<<" ";

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

for(int j = 1 + 1; j< size; j++){

if (array[j] < array[i]){

swap(array[j], array[i]);

cout<<"\nsorted\n";
for (int i = 0; i < size; i++){

cout<<array[i]<<" ";

int main(){

int unsorted[] = {64, 29, 86, 27, 32, 40, 14, 95, 35, 20}, size = 10;

sort_array(unsorted, size);

return 0;

Activity 5:

#include <iostream>

#include <string>

using namespace std;

class ContactEntry{

private:

string name, number, email;

public:

void setName(string n){name = n;}

string getName(void){return name;}


void setNumber(string num){ number = num;}

string getNumber(void){ return number;}

void setEmail(string eml){email = eml;}

string getEmail(void){return email;}

};

class ContactList{

public:

void printEntries();

};

void ContactList::printEntries(){

ContactEntry entry[10];

string name[10];

string number[10];

string email[10];

name[0] = "James Bajalan";


number[0] = "09498163228";

email[0] = "[email protected]";

name[1] = "Jessica Orbe";

number[1] = "08179897301";

email[1] = "[email protected]";

name[2] = "Christelle Leopoldo";

number[2] = "09084844165";

email[2] = "[email protected]";

name[3] = "Megan Tan";

number[3] = "08174562851";

email[3] = "[email protected]";

name[4] = "Kevin Enriquez";

number[4] = "09616618010";

email[4] = "[email protected]";

name[5] = " Jerome Santos";

number[5] = "08138284774";

email[5] = "[email protected]";

name[6] = "Prince Dumaog";


number[6] = "08173417006";

email[6] = "[email protected]";

name[7] = "Glenn Chiu";

number[7] = "0107572440";

email[7] = "[email protected]";

name[8] = "Joseph Arana";

number[8] = "08179783617";

email[8] = "[email protected]";

name[9] = "Matthew Campano";

number[9] = "09109703317";

email[9] = "[email protected]";

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

entry[i].setName(name[i]);

entry[i].setEmail(email[i]);

entry[i].setNumber(number[i]);

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

cout<<"\n=======================================\n";

cout << "Contact Name: "<< entry[i].getName() << endl;

cout << "Contact Number: "<< entry[i].getNumber() << endl;


cout << "Contact Email: " << entry[i].getEmail() << endl;

cout <<"=======================================\n\n\n";

int main(){

ContactList pbook = ContactList();

pbook.printEntries();

return 0;

You might also like