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;
}