0% found this document useful (0 votes)
6 views2 pages

S24 CMP120L LAB12 CString Pointer

Uploaded by

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

S24 CMP120L LAB12 CString Pointer

Uploaded by

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

American University of Sharjah Instructors: Dr.

Anas Al Majali
College of Engineering Lab Instructor: Sahar Mahmoud
Dept of Computer Science & Engg Office: ESB-1004B
P. O. Box 26666 Phone: 971-6-515-4944
Sharjah, UAE e-mail: skmahmoud@aus.edu
Semester: Spring 2024

CMP 120L– Programming I


Lab #12: Cstrings and Pointers

Note: using ChatGPT will be considered a violation of the AUS integrity code.

Objectives:
 To practice Cstrings.
 To practice declaring and initializing pointers.
 To practice using the & and * operators.

Using Visual Studio 2022, write the below programs, compile and provide screenshots of output.
Note: you are required to submit copy of the code + screenshots of program run for each exercise.

[3 pts] Exercise #1
Write a C++ program to help two friends compare their favorite books. The program should prompt the users
to input the titles of their favorite books using getline() method. Additionally, it should include a
compareBooks() function that utilizes the strcmp() function to compare the books entered by the users. If
the friends have the same book in common, the program should print a message indicating this. Otherwise, it
should inform them that they don't share the same favorite book and display each user's favorite book.

void compareBook(char book1[], char book2[]);

Sample output:

[4 pts] Exercise #2
Define a function named caesarCipher() that takes two parameters: a C-string representing the message to
be encrypted and an integer representing the shift value. Inside the function, iterate through each character
in the message: If the character is alphabetic, shift it by the specified amount in the alphabet.

In the main function: Declare a character array named message[] to store the user's input message. Prompt
the user to input a message and shift value. Call the caesarCipher function with the input message and shift
value to encrypt the message. Use isalpha() method which take a character as a parameter.

1
Sample output:

[3 pts] Exercise #3
Write a C++ program that perform the following:
a. Declare an integer pointer ptr, then use it to allocate memory for a new integer.
Print the address of the integer.
b. Assign a new value to the integer using user input via *ptr.
c. Declare an integer x and initialize it with the value pointed at by ptr.
d. Print the value of x using its own variable name.
e. Delete the integer pointed at by ptr, then point ptr to x.
f. Print the address of x using ptr.
g. Print the value of x using ptr.
Samples output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy