0% found this document useful (0 votes)
4 views5 pages

PF Lab 8 Manual

The document provides instructions for submitting C++ programming lab tasks, emphasizing the use of Visual Studio, proper code formatting, and meaningful variable names. It outlines ten specific tasks related to pointers, including calculating string length, reversing arrays, and manipulating C-strings. The learning objectives focus on demonstrating knowledge of arrays and problem-solving using pointers in C++.

Uploaded by

ahsan malik
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)
4 views5 pages

PF Lab 8 Manual

The document provides instructions for submitting C++ programming lab tasks, emphasizing the use of Visual Studio, proper code formatting, and meaningful variable names. It outlines ten specific tasks related to pointers, including calculating string length, reversing arrays, and manipulating C-strings. The learning objectives focus on demonstrating knowledge of arrays and problem-solving using pointers in C++.

Uploaded by

ahsan malik
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/ 5

Programming Fundamentals

Instructions:
 You must submit CPP files of the program in a folder, named your Registration
Number.
 You must upload your lab tasks on CMS.
 All program codes should be written in C/C++. Students should use Visual studio
compiler for coding.
 Indent and comment your code.
 Use meaningful variable names
 Plan your code carefully on a piece of paper before you implement it.

Learning Objectives:
 Demonstrate knowledge of basic arrays in programming C++. (Revision)
Blooms
CLO NO CLO STATEMENT Taxonomy PLO
Level

Create solutions for real-world issues while


staying within restrictions and making the
1 P3 5
most use of available resources by utilizing
sophisticated problem-solving methods.

Lab 09
Topic  POINTERS
 Reason for introducing pointers.
 Pointer declarations and initialization.
 Explaining the difference between pointer declaration and ordinary variable
declarations.
Objective  Taking address of (&) a variable.
 Dereferencing a pointer.
 Different types of constants involving pointers.
 Problem solving involving pointers.

______________________________________________________________________________
_____________________________________________________________________________
TASK TO DO
Task 1:
Write a C++ program to calculate the length of a C-string using pointer arithmetic. Do not use
any library functions like strlen().
Sample Output:
Enter a string: Hello World
Length of the string: 11
____________________________________________________________________________
Task 2:
Write a C++ program that takes 5 integers in an array and displays them using pointer notation
*(arr + i).
Sample Output:
Enter 5 integers: 1 2 3 4 5
You entered: 1 2 3 4 5
_____________________________________________________________________________

Task 3:
Write a C++ program to reverse an array of 5 integers using pointer notation *(arr + i).
Sample Output:
Enter 5 integers: 10 20 30 40 50
Reversed array: 50 40 30 20 10

Task 4:
Write a C++ program that reads 6 float numbers, stores them in an array, and prints them using
pointer subscript notation p[i].

Sample Output:
Enter 6 float numbers:
1.2 3.4 5.6 7.8 9.0 2.1
Array elements using pointer subscript notation:
1.2 3.4 5.6 7.8 9 2.1
_____________________________________________________________________________
Task 5:
Write a C++ program to convert all characters of a C-string to uppercase using pointers.
Sample output:
Enter a string: hello world
Uppercase string: HELLO WORLD
____________________________________________________________________________
Task 6:
Write a C++ program that calculates the average of 5 double numbers using a pointer with
subscript notation p[i].
Sample output:
Enter 5 double values: 10.5 20.0 30.5 40.5 50.5
Average: 30.4
__________________________________________________________________________
Task 7:
Write a C++ program that Replace vowels in a C-string with '*' using pointers.
Sample Output File:
Enter string = pointer
Updated string = p**nt*r
__________________________________________________________________________
Task 8:
Write a C++ program that Display the memory address and value of each element in an array
using pointer arithmetic.
Sample Output:
Enter number of elements: 2 4 6
Address: 0x7ffdxxxx, Value: 2
Address: 0x7ffdxxxx, Value: 4
Address: 0x7ffdxxxx, Value: 6
__________________________________________________________________________
Task 9:
Write a C++ program that uses pointers to swap two integers. The program should include a function
swapValues(int *a, int *b) that swaps the values using pointers. In the main() function, take two integer
inputs from the user, call the function, and display the values before and after swapping.
Sample Output:
Enter two integers: 5 10
Before swapping:
x = 5, y = 10

After swapping:
x = 10, y = 5
__________________________________________________________________________
Task 10:
Write a C++ program that Count how many even and odd numbers are in an array using pointer
arithmetic.
Sample output:
Enter numbers 3 2 6 7 9 10 11
Even numbers: 3
Odd numbers: 4

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

End of LAB 9 😊

You might also like