-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are all the files which we were assigned in the first semester to do them in C++ lab class.
- Loading branch information
0 parents
commit e078af7
Showing
73 changed files
with
2,768 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
//1. First we will get students' multiple subjects marks | ||
// and display them | ||
|
||
const int STUDENTS = 2; | ||
const int SUBJECTS = 3; | ||
int marks[STUDENTS][SUBJECTS]; | ||
|
||
for(int i=0; i<STUDENTS; i++) | ||
{ | ||
cout<<"**************************************\n"; | ||
cout<<"\tStudent "<<i+1<<endl; | ||
cout<<"**************************************\n"; | ||
for(int j=0; j<SUBJECTS; j++) | ||
{ | ||
cout<<"Enter marks for subject "<<j+1<<" : "; | ||
cin>>marks[i][j]; | ||
} | ||
} | ||
|
||
for(int i=0; i<STUDENTS; i++) | ||
{ | ||
cout<<"**************************************\n"; | ||
cout<<"\tStudent "<<i+1<<endl; | ||
cout<<"**************************************\n"; | ||
for(int j=0; j<SUBJECTS; j++) | ||
{ | ||
cout<<"Subject "<<j+1<<"\t"<<"Marks = "<<marks[i][j]<<endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
//1. First we will get students' multiple subjects marks | ||
// and display them | ||
//2. Then we will calculate each subject gpa | ||
|
||
const int STUDENTS = 2; | ||
const int SUBJECTS = 3; | ||
int marks[STUDENTS][SUBJECTS]; | ||
float subGpa[STUDENTS][SUBJECTS]; | ||
|
||
for(int i=0; i<STUDENTS; i++) | ||
{ | ||
cout<<"**************************************\n"; | ||
cout<<"\tStudent "<<i+1<<endl; | ||
cout<<"**************************************\n"; | ||
for(int j=0; j<SUBJECTS; j++) | ||
{ | ||
cout<<"Enter marks for subject "<<j+1<<" : "; | ||
cin>>marks[i][j]; | ||
} | ||
} | ||
|
||
for(int i=0; i<STUDENTS; i++) | ||
{ | ||
cout<<"**************************************\n"; | ||
cout<<"\tStudent "<<i+1<<endl; | ||
cout<<"**************************************\n"; | ||
for(int j=0; j<SUBJECTS; j++) | ||
{ | ||
if(marks[i][j] >= 87 && marks[i][j] <= 100) | ||
subGpa[i][j] = 4.0; | ||
else if(marks[i][j] >= 80 && marks[i][j] < 87) | ||
subGpa[i][j] = 3.5; | ||
else if(marks[i][j] >= 72 && marks[i][j] < 80) | ||
subGpa[i][j] = 3.0; | ||
else if(marks[i][j] >= 67 && marks[i][j] < 72) | ||
subGpa[i][j] = 2.5; | ||
else if(marks[i][j] >= 60 && marks[i][j] < 67) | ||
subGpa[i][j] = 2.0; | ||
else | ||
subGpa[i][j] = 0.0; | ||
cout<<"Subject "<<j+1<<"\t"<<"Marks = "<<marks[i][j]<<"\tGPA = "<<subGpa[i][j]<<endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
//1. First we will get students' multiple subjects marks | ||
// and display them | ||
//2. Then we will calculate each subject gpa | ||
//3. Finally, we will find the gpa of each student in a | ||
// semester | ||
// gpa = SUM(each subject gpa * credit hours)/total credit hours | ||
// array for credit hours, size will be SUBJECTS | ||
// array for semester gpa, size will be STUDENTS | ||
|
||
const int STUDENTS = 2; | ||
const int SUBJECTS = 3; | ||
int marks[STUDENTS][SUBJECTS]; | ||
float subGpa[STUDENTS][SUBJECTS]; | ||
float semGpa[STUDENTS]; | ||
int crdHrs[SUBJECTS]; | ||
|
||
for(int i=0; i<SUBJECTS; i++) | ||
{ | ||
cout<<"Enter the credit hours for subject "<<i+1<<" : "; | ||
cin>>crdHrs[i]; | ||
} | ||
int totalCrdHrs = 0; | ||
for(int i=0; i<SUBJECTS; i++) | ||
totalCrdHrs += crdHrs[i]; | ||
|
||
for(int i=0; i<STUDENTS; i++) | ||
{ | ||
cout<<"**************************************\n"; | ||
cout<<"\tStudent "<<i+1<<endl; | ||
cout<<"**************************************\n"; | ||
for(int j=0; j<SUBJECTS; j++) | ||
{ | ||
cout<<"Enter marks for subject "<<j+1<<" : "; | ||
cin>>marks[i][j]; | ||
} | ||
} | ||
float sum; | ||
for(int i=0; i<STUDENTS; i++) | ||
{ | ||
sum = 0.0; | ||
cout<<"**************************************\n"; | ||
cout<<"\tStudent "<<i+1<<endl; | ||
cout<<"**************************************\n"; | ||
for(int j=0; j<SUBJECTS; j++) | ||
{ | ||
if(marks[i][j] >= 87 && marks[i][j] <= 100) | ||
subGpa[i][j] = 4.0; | ||
else if(marks[i][j] >= 80 && marks[i][j] < 87) | ||
subGpa[i][j] = 3.5; | ||
else if(marks[i][j] >= 72 && marks[i][j] < 80) | ||
subGpa[i][j] = 3.0; | ||
else if(marks[i][j] >= 67 && marks[i][j] < 72) | ||
subGpa[i][j] = 2.5; | ||
else if(marks[i][j] >= 60 && marks[i][j] < 67) | ||
subGpa[i][j] = 2.0; | ||
else | ||
subGpa[i][j] = 0.0; | ||
cout<<"Subject "<<j+1<<"\t"<<"Marks = "<<marks[i][j]<<"\tGPA = "<<subGpa[i][j]<<endl; | ||
sum += subGpa[i][j]*crdHrs[j]; | ||
} | ||
|
||
semGpa[i] = sum/totalCrdHrs; | ||
cout<<"Semester GPA = "<<semGpa[i]<<endl; | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <iostream> | ||
using namespace std; | ||
struct employee { | ||
string name; | ||
int deptNo; | ||
float salary; | ||
int awardsYears[3]; | ||
}; | ||
|
||
|
||
int main() | ||
{ | ||
employee e1; | ||
e1.name = "Irfan"; | ||
e1.deptNo = 1; | ||
e1.salary = 30; | ||
e1.awardsYears[0] = 2012; | ||
e1.awardsYears[1] = 2013; | ||
e1.awardsYears[2] = 2015; | ||
|
||
cout<<e1.name<<endl; | ||
cout<<e1.deptNo<<endl; | ||
cout<<e1.salary<<endl; | ||
cout<<e1.awardsYears[1]; | ||
|
||
employee e2 = {"Khan", 2, 25.0, {2016, 2017, 2019}}; | ||
cout<<endl<<e2.name<<endl; | ||
cout<<e2.deptNo<<endl; | ||
cout<<e2.salary<<endl; | ||
cout<<e2.awardsYears[1]; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <iostream> | ||
using namespace std; | ||
//int sum(int a[], int s); | ||
int sum(int[], int); | ||
int sum2(int a[][2], int r, int c); | ||
int main() | ||
{ | ||
// const int SIZE = 3; | ||
// int n[SIZE] = {2, 3, 5}; | ||
// cout<<"Access memory violation: "<<n[100]<<endl; | ||
// cout<<"Address of array: "<<n<<endl; | ||
// cout<<"First element of the array: "<<*n<<endl; | ||
// cout<<"SUM = "<<sum(n, SIZE)<<endl; | ||
|
||
int d2[3][2] = {{3, 1}, {5,4}, {5, 2}}; | ||
cout<<"Sum of 2D = "<<sum2(d2, 3, 2)<<endl; | ||
//cout<<n<<endl; | ||
cout<<d2<<endl; | ||
return 0; | ||
} | ||
|
||
int sum(int a[], int s) | ||
{ | ||
// cout<<a<<endl; | ||
int result = 0; | ||
for(int i=0; i<s; i++) | ||
result += a[i]; | ||
return result; | ||
} | ||
|
||
int sum2(int a[][2], int r, int c) | ||
{ | ||
int result = 0; | ||
for(int i=0; i<r; i++) | ||
{ | ||
for(int j=0; j<c; j++) | ||
result += a[i][j]; | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <iostream> | ||
using namespace std; | ||
// Sharif Ullah Danish | ||
void Expenses(int p,int m,int Data[][6]); | ||
|
||
int main() | ||
{ | ||
const int PER=3; | ||
const int MONTH=6; | ||
int data[PER][MONTH]; | ||
|
||
Expenses(PER,MONTH,data); | ||
|
||
|
||
return 0; | ||
} | ||
|
||
void Expenses( int p, int M,int Data[][6]){ | ||
|
||
// | ||
for(int i=0; i<p; i++) | ||
{ | ||
int total=0, max=0, min=999999; | ||
cout<<"\n User "<<i+1<<" Data: "<<endl; | ||
|
||
for(int j=0; j<M; j++) | ||
|
||
{ | ||
cout<<"Enter expenses for month "<<j+1<<": "; | ||
cin>>Data[i][j]; | ||
|
||
total+=Data[i][j]; | ||
if(Data[i][j]>max) max = Data[i][j]; | ||
if(Data[i][j]<min) min = Data[i][j]; | ||
} | ||
|
||
// we use loop for just stars | ||
|
||
for(int a=0; a<40; a++) | ||
cout<<"-"; | ||
|
||
cout<<"\n User "<<i+1<<" \t 6 month expenses \n"; | ||
|
||
for(int a=0; a<40; a++) | ||
cout<<"-"; | ||
|
||
cout<<"\n Total is: "<<total; | ||
cout<<"\n Highest is: "<<max; | ||
cout<<"\n Lowest is: "<<min<<endl; | ||
|
||
// we use loop for just stars | ||
|
||
for(int a=0; a<40; a++) | ||
{ | ||
cout<<"*"; | ||
} | ||
|
||
|
||
} | ||
// | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
using namespace std; | ||
// Sharif Ullah Danish | ||
|
||
int main() | ||
{ | ||
const int PER=3; | ||
const int MONTH=6; | ||
int data[PER][MONTH]; | ||
|
||
|
||
for(int i=0; i<PER; i++) | ||
{ | ||
int total=0, max=0, min=99999; | ||
cout<<"\n User "<<i+1<<" Data: "<<endl; | ||
|
||
for(int j=0; j<MONTH; j++) | ||
|
||
{ | ||
cout<<"Enter expenses for month "<<j+1<<": "; | ||
cin>>data[i][j]; | ||
|
||
total+=data[i][j]; | ||
if(data[i][j]>max) max = data[i][j]; | ||
if(data[i][j]<min) min = data[i][j]; | ||
} | ||
|
||
// we use loop for just stars | ||
|
||
for(int a=0; a<40; a++) | ||
cout<<"-"; | ||
|
||
cout<<"\n User "<<i+1<<" \t 6 month expenses \n"; | ||
|
||
for(int a=0; a<40; a++) | ||
cout<<"-"; | ||
|
||
cout<<"\n Total is: "<<total; | ||
cout<<"\n Highest is: "<<max; | ||
cout<<"\n Lowest is: "<<min<<endl; | ||
|
||
// we use loop for just stars | ||
|
||
for(int a=0; a<40; a++) | ||
{ | ||
cout<<"*"; | ||
} | ||
|
||
|
||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.