0% found this document useful (0 votes)
52 views4 pages

Hamdard University Islamabad Campus: Assignment No

The document is a lab assignment for an Object Oriented Programming course. It contains two programming tasks. The first task requires writing a program that introduces integer variables and pointers, sets their values, and prints the addresses and values. The second task requires writing a program that inputs an array, calls a function passing the array, and the function determines the count of even and prime numbers in the array.

Uploaded by

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

Hamdard University Islamabad Campus: Assignment No

The document is a lab assignment for an Object Oriented Programming course. It contains two programming tasks. The first task requires writing a program that introduces integer variables and pointers, sets their values, and prints the addresses and values. The second task requires writing a program that inputs an array, calls a function passing the array, and the function determines the count of even and prime numbers in the array.

Uploaded by

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

Page 1 of 4

Hamdard University Islamabad Campus


Hamdard Institute of Engineering & Technology
Department of Computing

Program: BS Computer Science

Course Number CS122


Course Title Object Oriented Programming
Semester/Year Fall 2020

Instructor Ms. Saadia Mooqaddas

ASSIGNMENT No. 02

Assignment Title Lab NO 2

Submission Date
Due Date

Student Name Muhammad Umer Farooq


Student CMS-ID 445-2020
Signature*

*By signing above, you attest that you have contributed to this submission and
confirm that all work you have contributed to this submission is your own work. Any
suspicion of copying or plagiarism in this work will result in an investigation of
Academic Misconduct and may result in a “0” on the work, an “F” in the course, or
possibly more severe penalties.
Page 2 of 4

Lab Tasks
Task # 1
Program Statement:
Introduce int variables x and y and int* pointer variables p and q. Set x to 2, y to 8, p to the
address of x, and q to the address of y. Then print the following information
(1) The address of x and the value of x.
(2) The value of p and the value of *p.
(3) The address of y and the value of y.
(4) The value of q and the value of *q.
(5) The address of p (not its contents!).
(6) The address of q (not its contents!).

Program Code:
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
int x,y;
int *p,*q;
x=2;
y=8;
p=&x;
q=&y;
cout<<"The address of x is "<<&x<<" and the value of x is "<<x<<endl;
cout<<"The value of p is "<<p<<" and the value of *p is "<<*p<<endl;
cout<<"The address of y is "<<&y<<" and the value of y is "<<y<<endl;
cout<<"The value of q is "<<q<<" and the value of *q "<<*q<<endl;
cout<<"The address of p (not its contents!) is "<<&p<<endl;
cout<<"The address of q (not its contents!) is "<<&q<<endl;
System(“pause”);
}
Page 3 of 4

Program Output:

Task #2
Program Statement:
Write a program that inputs an array of 10 elements. The program then calls a function, sending
it the array as an input argument and the function then determines the count of even and prime
numbers in the array and display the result.

Program code:
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
int arr[10], i, p=0, c, prime=0;
for(i=0;i<10;i++)
{
cout<<"Enter an integer:";
cin>>arr[i];
}
Page 4 of 4

cout<<"The prime numbers are:\n";


for(i=0;i<10;i++)
{
if(arr[i]>1)
{
p=1;
for(c=2;c<arr[i];c++)
{
if(arr[i]%c==0)
{
p=0;
break;
}
}
}
if(p==1)
{
cout<<arr[i]<<" is a prime number.\n";
prime++;
}
}
cout<<"total prime numbers entered by the user are: "<<prime<<endl;
system(“pause”);
Return 0;
}

Program Output:

You might also like