0% found this document useful (0 votes)
8 views

Javascript Code

javascript code

Uploaded by

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

Javascript Code

javascript code

Uploaded by

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

class Course {

constructor(courseName, creditHours, grade) {


this.courseName = courseName;
this.creditHours = creditHours;
this.grade = grade;
}
}

class Semester {
constructor(semesterNumber, courses) {
this.semesterNumber = semesterNumber;
this.courses = courses;
}

calculateGPA() {
let totalGradePoints = 0;
let totalCreditHours = 0;

this.courses.forEach(course => {
totalGradePoints += course.grade * course.creditHours;
totalCreditHours += course.creditHours;
});

return totalGradePoints / totalCreditHours;


}
}

class Student {
constructor(name, semesters) {
this.name = name;
this.semesters = semesters;
}

calculateCGPA() {
let totalGPA = 0;
this.semesters.forEach(semester => {
totalGPA += semester.calculateGPA();
});

return totalGPA / this.semesters.length;


}
}

function main() {
let students = [];

let numberOfStudents = parseInt(prompt("Enter the number of students: "));

for (let i = 0; i < numberOfStudents; i++) {


let studentName = prompt(`Enter the name of student ${i + 1}: `);

let numberOfSemesters = parseInt(prompt(`Enter the number of semesters for


${studentName}: `));
let semesters = [];

for (let j = 0; j < numberOfSemesters; j++) {


let semesterNumber = j + 1;
let numberOfCourses = parseInt(prompt(`Enter the number of courses in
semester ${semesterNumber}: `));
let courses = [];

for (let k = 0; k < numberOfCourses; k++) {


let courseName = prompt("Enter the course name: ");
let creditHours = parseInt(prompt(`Enter credit hours for $
{courseName}: `));
let grade = parseFloat(prompt(`Enter grade for ${courseName}: `));

courses.push(new Course(courseName, creditHours, grade));


}

semesters.push(new Semester(semesterNumber, courses));


}

students.push(new Student(studentName, semesters));


}

students.forEach(student => {
console.log(`CGPA of ${student.name} is: $
{student.calculateCGPA().toFixed(2)}`);
});
}

// Run the program


main();

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy