0% found this document useful (0 votes)
4 views13 pages

OOP SemesterProject

The document outlines a semester project in Object Oriented Programming submitted by students to their instructor. It includes a C++ program that generates random academic records for students, calculates their grades, and outputs the results to a text file. Additionally, it features another program that reads the generated records and computes the SGPA for a specified student based on their performance in various subjects.
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)
4 views13 pages

OOP SemesterProject

The document outlines a semester project in Object Oriented Programming submitted by students to their instructor. It includes a C++ program that generates random academic records for students, calculates their grades, and outputs the results to a text file. Additionally, it features another program that reads the generated records and computes the SGPA for a specified student based on their performance in various subjects.
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

DEPARTMENT OF TECHNOLOGY (IET)

SUBMITED BY:
Muhammad Ali Sheikh (70151489)
Muneeb Ur Rehman (70149177)
Syed Muhammad Ali Shah(70142727)

SUBMITED TO: SIR WASEEEM NAZAR


SECTION: (J)
Submitted On: 14 June, 2025
Semester Project

OBJECT ORIENTED PROGRAMMING


[Link]
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

struct ExamComponent {
string type;
int totalMarks;
int obtainedMarks;
};

struct Subject {
string code;
string name;
int creditHours;
ExamComponent exams[11];
int totalObtained;
int totalMarks;
double assignmentWeightage;
double quizWeightage;
};
struct Student {
string sapID;
string name;
string semester;
Subject subjects[5];
};

string randomSAP() {
int randomPart = rand() % 9000 + 1000;
return "7015" + to_string(randomPart);
}

int randomMarks(int maxMarks) {


int minMarks = maxMarks * 60 / 100;
return minMarks + (rand() % (maxMarks - minMarks + 1));
}

int main() {
srand(time(0));

string subjectCodes[5] = {"CSS02226", "CSS02227", "CSS02228", "CSS02229", "CSS02230"};


string subjectNames[5] = {"OOP", "OS", "DataCom", "Maths", "Embedded"};
int creditHours[5] = {4, 3, 3, 3, 3};
string semester = "Winter 2025";

ofstream outFile("student_academic_records.txt");
if (!outFile) {
cerr << "Error creating output file!" << endl;
return 1;
}
for (int s = 1; s <= 40; ++s) {
Student student;
[Link] = randomSAP();
[Link] = "Name_" + to_string(s);
[Link] = semester;

outFile << "Student: " << [Link] << " (" << [Link] << "), Semester: " << semester << "\
n";

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


Subject& subj = [Link][i];
[Link] = subjectCodes[i];
[Link] = subjectNames[i];
[Link] = creditHours[i];

int idx = 0;
int finalMarks = ([Link] == "Maths") ? 50 : 40;
int midMarks = ([Link] == "Maths") ? 30 : 20;
int labMarks = ([Link] == "Maths") ? 0 : 20;

[Link][idx++] = {"Final", finalMarks, randomMarks(finalMarks)};


[Link][idx++] = {"Mid", midMarks, randomMarks(midMarks)};
[Link][idx++] = {"Lab", labMarks, (labMarks > 0 ? randomMarks(labMarks) : 0)};

int assignmentTotal = 0, assignmentObtained = 0;


for (int j = 0; j < 4; ++j) {
int obtained = randomMarks(10);
[Link][idx++] = {"Assignment" + to_string(j + 1), 10, obtained};
assignmentTotal += 10;
assignmentObtained += obtained;
}
int quizTotal = 0, quizObtained = 0;
for (int j = 0; j < 4; ++j) {
int obtained = randomMarks(10);
[Link][idx++] = {"Quiz" + to_string(j + 1), 10, obtained};
quizTotal += 10;
quizObtained += obtained;
}

[Link] = finalMarks + midMarks + labMarks + 40 + 40;


[Link] = 0;
for (int j = 0; j < 11; ++j) {
[Link] += [Link][j].obtainedMarks;
}

[Link] = (assignmentObtained / (double)assignmentTotal) * 10;


[Link] = (quizObtained / (double)quizTotal) * 10;

outFile << "Subject: " << [Link] << " (" << [Link] << "), Credit Hours: " << [Link]
<< "\n";
for (int j = 0; j < 11; ++j) {
outFile << " " << [Link][j].type << ": "
<< [Link][j].obtainedMarks << "/" << [Link][j].totalMarks << "\n";
}

outFile << " Total: " << [Link] << "/" << [Link] << "\n";
outFile << " Assignment Weightage: " << fixed << setprecision(2) << [Link]
<< "/10\n";
outFile << " Quiz Weightage: " << fixed << setprecision(2) << [Link] << "/10\n";
outFile << "\n";
}

outFile << "---------------------------------------------------------\n";


}
[Link]();
cout << "Text file 'student_academic_records.txt' has been successfully created.\n";
return 0;
}

Output:

student_academic_records.txt
2. [Link]
#include <iostream>

#include <fstream>

#include <string>

#include <sstream>

#include <vector>

#include <iomanip>

using namespace std;

struct SubjectData {

string code;

string name;

int creditHours;
int totalObtained;

int totalMarks;

};

struct StudentData {

string sapID;

string name;

string semester;

vector<SubjectData> subjects;

};

double getGradePoint(double percentage) {

if (percentage >= 85) return 4.00;

else if (percentage >= 80) return 3.75;

else if (percentage >= 75) return 3.50;

else if (percentage >= 70) return 3.00;

else if (percentage >= 65) return 2.50;

else if (percentage >= 50) return 2.00;

else return 0.00;

int main() {

ifstream inFile("student_academic_records.txt");

if (!inFile) {

cerr << "Error: Cannot open file student_academic_records.txt\n";

return 1;

cout << "Enter SAP ID to search: ";

string searchSAP;

getline(cin, searchSAP);
string line;

StudentData student;

bool studentFound = false;

bool insideStudent = false;

while (getline(inFile, line)) {

if ([Link]()) continue;

// Detect new student line: "Student: Name_1 (70151234), Semester: Winter 2025"

if ([Link]("Student: ") == 0) {

// Parse SAP ID

size_t sapStart = [Link]('(');

size_t sapEnd = [Link](')');

if (sapStart == string::npos || sapEnd == string::npos || sapEnd <= sapStart) continue;

string sapID = [Link](sapStart + 1, sapEnd - sapStart - 1);

if (sapID == searchSAP) {

studentFound = true;

insideStudent = true;

// Parse name and semester

[Link] = [Link](9, sapStart - 10); // "Student: " is length 9

[Link] = sapID;

size_t semPos = [Link]("Semester: ");

if (semPos != string::npos) {

[Link] = [Link](semPos + 10);

} else {

[Link] = "";

}
[Link]();

} else {

// If we had found the student previously and now a new student starts, stop reading

if (insideStudent) break;

insideStudent = false;

continue;

if (!studentFound || !insideStudent) continue;

// Parse subjects

// Format: Subject: OOP (CSS02226), Credit Hours: 4

if ([Link]("Subject: ") == 0) {

SubjectData subj;

// Parse subject name and code

size_t nameStart = 9; // after "Subject: "

size_t codeStart = [Link]('(');

size_t codeEnd = [Link](')');

if (codeStart == string::npos || codeEnd == string::npos || codeEnd <= codeStart) continue;

[Link] = [Link](nameStart, codeStart - nameStart - 1);

[Link] = [Link](codeStart + 1, codeEnd - codeStart - 1);

// Parse credit hours

size_t creditPos = [Link]("Credit Hours: ");

if (creditPos != string::npos) {

string creditStr = [Link](creditPos + 14);

[Link] = stoi(creditStr);

} else {

[Link] = 0;
}

// Now read next 11 exam lines + total lines for this subject

int obtainedTotal = 0;

int totalMarks = 0;

// We expect 11 exam lines + 3 more lines for total and weightages

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

if (!getline(inFile, line)) break;

// example line: " Final: 36/40"

size_t colonPos = [Link](':');

if (colonPos == string::npos) continue;

// For Total line: " Total: 120/140"

if ([Link]("Total: ") != string::npos) {

size_t slashPos = [Link]('/');

if (slashPos != string::npos) {

int obtained = stoi([Link](colonPos + 2, slashPos - (colonPos + 2)));

int total = stoi([Link](slashPos + 1));

obtainedTotal = obtained;

totalMarks = total;

// We don't need to parse assignments/quizzes weightage lines for SGPA

[Link] = obtainedTotal;

[Link] = totalMarks;

[Link].push_back(subj);

}
}

if (!studentFound) {

cout << "Student with SAP ID " << searchSAP << " not found.\n";

return 0;

// Calculate SGPA

cout << "\nStudent: " << [Link] << " (" << [Link] << "), Semester: " << [Link] << "\n";

double totalPoints = 0.0;

int totalCredits = 0;

for (auto &subj : [Link]) {

double percent = ([Link] > 0) ? (100.0 * [Link] / [Link]) : 0;

double gp = getGradePoint(percent);

totalPoints += gp * [Link];

totalCredits += [Link];

cout << "Subject: " << [Link] << " (" << [Link] << ")\n";

cout << fixed << setprecision(2)

<< " Marks: " << [Link] << "/" << [Link]

<< ", Percentage: " << percent << "%, Grade Point: " << gp << "\n";

double sgpa = (totalCredits > 0) ? (totalPoints / totalCredits) : 0.0;

cout << fixed << setprecision(3) << "\nSGPA: " << sgpa << "\n";

return 0;

}
Output:

You might also like