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

GRANBY COLLEGES OF SCIENCE & TECHNOLOGY

College of Information and Communication Technology


Naic, Cavite, Philippines
Tel: (046) 412-0437

Name:
GRANBY COLLEGES OF SCIENCE & TECHNOLOGY
College of Information and Communication Technology
Naic, Cavite, Philippines
Tel: (046) 412-0437

General Smith of the First Infantry Division is tasked on assigning his men on different locations throughout the
Pacific Region. The general, being known for his gentle leadership, decided to let his men choose on which
location they wanted to be assigned. The available locations are Guam, Palau, Samoa, Hawaii, and Yap. The
general, using his knowledge on programming because he once took a crash course about it, used the C++
language to create a program which will ask the soldier about their name, their age, the location where they
wanted to be assigned, and what month they wanted to be appointed. The general also used the concept of
struct to group the data of the soldier. What code should the general write, and what will be the output?

7. Write a C++ program where the user can enter two integers, and then display the pointers of each two integers
entered by the user, and then check if the sum of the two integers is either odd or even. If the sum is even then
display the pointer of the first integer entered, and if the sum is odd then display the pointer of the second
integer entered. See the sample output below.

8. THE SARAH PROBLEM

Sarah wants to use pointers to swap the values of two variables, x and y. She creates two pointer variables,
*ptr1 and *ptr2, and assigns them the addresses of x and y, respectively. After swapping the values using the
pointers, she wants to display the updated values of x and y. What would be the output and the source code for
this?

You might also like