0% found this document useful (0 votes)
8 views6 pages

Assignment 3 PF

The document contains programming assignments submitted by Alliya Fatima, focusing on programming fundamentals. It includes four C++ programs: the first calculates the sum of four integers, the second searches for a value in a 2D array, the third updates and displays employee salary details, and the fourth computes the sum of an array using pointers. Each program is accompanied by its respective code and output.

Uploaded by

alliyafatima78
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)
8 views6 pages

Assignment 3 PF

The document contains programming assignments submitted by Alliya Fatima, focusing on programming fundamentals. It includes four C++ programs: the first calculates the sum of four integers, the second searches for a value in a 2D array, the third updates and displays employee salary details, and the fourth computes the sum of an array using pointers. Each program is accompanied by its respective code and output.

Uploaded by

alliyafatima78
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/ 6

Name: Alliya Fatima (BS-AI)

Subject: Programming Fundamentals

Roll no: BSAI9248206

Assignment: 3

Submitted to: Sir Shahid


Program 1:
#include<iostream>
using namespace std;
int main()
{
int arr[4];
int sum=0;
for(int i=0; i<4 ;i++)
{
cin>>arr[i];
sum+=arr[i];
}
cout<<sum<endl;
return 0;
}
Output:

Program 2:

#include<iostream>
using namespace std;
int main()
{
int rows,columns;
cout<<"enter the number of rows and columns = "; cin>>rows>>columns;
int arr[rows][columns];
cout<<"enter the elements = "<<endl;
for(int i=0 ;i<rows ;i++){
for(int j=0 ;j<columns ;j++){
cin>>arr[i][j];
}
}
int x;
cout<<"Enter the value you want to find = ";
cin>>x;

for(int i=0 ;i<rows ;i++){


for(int j=0 ;j<columns ;j++){
if (arr[i][j]==x){
cout<<"The number is at row "<<i+1<<" and column " <<j+1<<endl;
return 0;
}
}
cout<<endl;
}
return 0;
}

Program 3:
#include <iostream>
#include <string>
using namespace std;
struct Employee {
string name;
int id;
float salary;
};
Employee updateSalary(Employee emp, float percentage) {
emp.salary += emp.salary * (percentage / 100);
return emp;
}
void displayEmployee(Employee emp) {
cout << "Employee Details:";
cout << "Name: " << emp.name << endl;
cout << "ID: " << emp.id << endl;
cout << "Salary: " << emp.salary << endl;
}
int main() {
Employee emp;
cout << "Enter employee's name: ";
getline(cin, emp.name);
cout << "Enter employee's ID: ";
cin >> emp.id;
cout << "Enter employee's salary: ";
cin >> emp.salary;
float percentage;
cout << "Enter the percentage increase in salary: ";
cin >> percentage;
emp = updateSalary(emp, percentage);
displayEmployee(emp);
return 0;
}

Program 4:
#include <iostream>
using namespace std;
int main()
{
int arr[] = {10, 20, 30, 40, 50};
int size = sizeof(arr) / sizeof(arr[0]);
int* ptr = arr;
int sum = 0;
for (int i = 0; i < size; i++) {
sum += *ptr;
ptr++;
}
cout << "The sum of all elements in the array is: " << sum << endl;
return 0;
}

You might also like