0% found this document useful (0 votes)
39 views

Assignment No. 5 (CLO-3) : Programming Fundamentals 19-EE-116 Department

The document contains an assignment submission for a programming fundamentals course. It includes a C++ program that reads float numbers from the user, stores them in an array, calculates the average using pointers, and prints the result. It also answers two true/false questions - that two pointers pointing to different arrays cannot be meaningfully compared, and that an array name cannot be used to refer to another memory location like a pointer can.

Uploaded by

Haroon Malik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Assignment No. 5 (CLO-3) : Programming Fundamentals 19-EE-116 Department

The document contains an assignment submission for a programming fundamentals course. It includes a C++ program that reads float numbers from the user, stores them in an array, calculates the average using pointers, and prints the result. It also answers two true/false questions - that two pointers pointing to different arrays cannot be meaningfully compared, and that an array name cannot be used to refer to another memory location like a pointer can.

Uploaded by

Haroon Malik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

 Assignment No.

5 (CLO-3)
Subject: Programming Fundamentals (CS-1233)
Name: haroon- malik ; section: d; REG NO: 19-EE-116
Department: electrical engineering
Submitted to: dr. qamas gul
Date: 05-09-2020

Q. No. 1: Analyze and outline the following problem statement into the C++
program using Pointers.

a) Write a program that reads a group of numbers from the user and places them in an array of type float.
Once the numbers are stored in the array, the program should average them and print the result. Use
pointer notation wherever possible.

ANSWER:

// finds average of numbers typed by user

#include <iostream>

using namespace std;

int main()

float flarr[100]; //array for numbers

char ch; //user decision

int num = 0; //counts numbers input

do

cout << "Enter number: "; //get numbers from user

cin >> *(flarr+num++); //until user answers 'n'

cout << " Enter another (y/n)? ";


cin >> ch;

while(ch != 'n');

float total = 0.0; //total starts at 0

for(int k=0; k<num; k++) //add numbers to total

total += *(flarr+k);

float average = total / num; //find and display average

cout << "Average is " << average << endl;

return 0;

Output:

Source File:

assign 5.cpp

b) State whether the following are true or false. If false, explain why.
I) Two pointers that point to different arrays cannot be compared meaningfully.

II) Because the name of an array is a pointer to the first element of the array, array names can be
manipulated in precisely the same manner as pointers.
Answer:

I) True
II) False, an array name cannot be used to refer to another location in memory.

You might also like