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

Assignment 9

The document outlines three sets of C++ programming assignments focused on string manipulation and pointer operations. Each assignment includes specific tasks such as replacing spaces with hyphens, checking for anagrams, swapping numbers, finding maximum and minimum values in an array, and copying strings using pointers. Constraints are provided for each task, including character limits and data types.

Uploaded by

pk24mmb0a53
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 views3 pages

Assignment 9

The document outlines three sets of C++ programming assignments focused on string manipulation and pointer operations. Each assignment includes specific tasks such as replacing spaces with hyphens, checking for anagrams, swapping numbers, finding maximum and minimum values in an array, and copying strings using pointers. Constraints are provided for each task, including character limits and data types.

Uploaded by

pk24mmb0a53
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/ 3

ASSIGNMENT 9

SET 1

1. Write a C++ program to replace all spaces in a given string with hyphens ('-') using a
predefined string function and simple logic.
Constraints:
 The input string can have at most 100 characters.
 The string consists of uppercase and lowercase English letters (A-Z, a-z), spaces, and
punctuation.

2. Write a C++ program to check whether two given strings are anagrams of each other using
pointers. Two strings are considered anagrams if they contain the same characters with the
same frequency but in a different order.
Constraints:
 Both input strings should contain at most 100 characters.
 The strings may contain only lowercase English letters (a-z).

3. Write a C++ program to swap two numbers using pointers, without using a third variable. The
program should take two integer inputs, swap their values using pointer dereferencing, and
display the swapped values.
Constraints:
 The numbers should be integers between -100,000 and 100,000.
 The program must not use a third variable for swapping.
 Use only pointer operations for swapping.

4. Write a C++ program to find the maximum and minimum elements in an array using pointers.
The program should take an array of integers as input and use pointer traversal to determine
the largest and smallest values.
Constraints:
 The array size should be between 1 and 100.
 The elements of the array should be integers between -10,000 and 10,000.
 The program should traverse the array only once using pointers.

5. Write a C++ program to find the length of a string using pointers, without using the built-in
strlen() function. The program should take a string as input, use pointer traversal to count
the number of characters, and display the length of the string.
Constraints:
 The input string should contain at most 100 characters.
 The string may contain uppercase/lowercase letters, digits, and spaces.
 The program should use only pointer arithmetic for traversal, without array indexing.

SET 2
1. Write a C++ program to check whether a given string is a palindrome or not. A string is
considered a palindrome if it reads the same forward and backward. Your program should
determine whether the input string meets this condition.
Constraints:
 The input string can have at most 100 characters.
 The string consists of only lowercase English letters (a-z).
 The comparison should be case-sensitive ("Madam" is not the same as "madam").

2. Write a C++ program to generate and print all possible substrings of a given string using
pointers. The program should take a string as input and generate all contiguous substrings.
Constraints:
 The input string should have at most 100 characters.
 The string consists of only lowercase English letters (a-z).
 Substrings should be printed in lexicographical order based on their starting index.

3. Write a C++ program to demonstrate pointer arithmetic by performing the following


operations on an array:
Increment (ptr++) – Move the pointer to the next element.
Decrement (ptr--) – Move the pointer to the previous element.
Addition (ptr + n) – Move the pointer forward by n positions.
Subtraction (ptr - n) – Move the pointer backwards by n positions.
The program should take an array of integers as input, apply pointer arithmetic, and display
the results.
Constraints:
 The array size should be between 1 and 100.
 The elements of the array should be integers between -10,000 and 10,000.
 The pointer operations should not access out-of-bounds memory.

4. Write a C++ program to reverse an array using pointers. The program should take an array of
integers as input, use pointer arithmetic to swap elements in place and display the reversed
array.
Constraints:
 The array size should be between 1 and 100.
 The elements of the array should be integers between -10,000 and 10,000.
 The reversal should be performed in-place using only pointers, without using extra
memory.

5. Write a C++ program to copy a string into another string using pointers, without using the
built-in strcpy() function. The program should take an input string, copy it to another
character array using pointer dereferencing, and display the copied string.
Constraints:
 The input string should contain at most 100 characters.
 The destination array should be large enough to store the copied string.
 The program should use only pointer arithmetic for copying, without array indexing.

SET 3
1. Write a C++ program to replace all spaces in a given string with hyphens ('-') using a
predefined string function and simple logic.
Constraints:
 The input string can have at most 100 characters.
 The string consists of uppercase and lowercase English letters (A-Z, a-z), spaces, and
punctuation.

2. Write a C++ program to check whether two given strings are anagrams of each other using
pointers. Two strings are considered anagrams if they contain the same characters with the
same frequency but in a different order.
Constraints:
 Both input strings should contain at most 100 characters.
 The strings may contain only lowercase English letters (a-z).

3. Write a C++ program to swap two numbers using pointers, without using a third variable. The
program should take two integer inputs, swap their values using pointer dereferencing, and
display the swapped values.
Constraints:
 The numbers should be integers between -100,000 and 100,000.
 The program must not use a third variable for swapping.
 Use only pointer operations for swapping.

4. Write a C++ program to find the maximum and minimum elements in an array using pointers.
The program should take an array of integers as input and use pointer traversal to determine
the largest and smallest values.
Constraints:
 The array size should be between 1 and 100.
 The elements of the array should be integers between -10,000 and 10,000.
 The program should traverse the array only once using pointers.

5. Write a C++ program to copy a string into another string using pointers, without using the
built-in strcpy() function. The program should take an input string, copy it to another
character array using pointer dereferencing, and display the copied string.
Constraints:
 The input string should contain at most 100 characters.
 The destination array should be large enough to store the copied string.
 The program should use only pointer arithmetic for copying, without array indexing.
Output Format:
Print "Strings are equal" if both strings are identical.
Print "First string is greater" if S1 > S2 lexicographically.
Print "First string is smaller" if S1 < S2 lexicographically.

You might also like