Skip to content

Commit 735d0c3

Browse files
Add files via upload
1 parent 21460b4 commit 735d0c3

File tree

5 files changed

+240
-0
lines changed

5 files changed

+240
-0
lines changed

12 - Inheritance/Solution.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdio.h>
2+
3+
int main(void)
4+
{
5+
char first[11], last[11];
6+
char grade;
7+
int ID;
8+
9+
int score_num;
10+
int score;
11+
int avg, cnt;
12+
13+
scanf("%s %s %d", first, last, &ID);
14+
scanf("%d", &score_num);
15+
for(avg=0, cnt=0;cnt<score_num;cnt++)
16+
{
17+
scanf("%d", &score);
18+
avg += score;
19+
}
20+
21+
avg = avg / cnt;
22+
printf("Name : %s, %s\n", first, last);
23+
printf("ID : %d\n", ID);
24+
25+
//Aditya Seth
26+
if ((100 >= avg) && (avg >= 90)) printf("Grade : O\n", avg / cnt);
27+
else if (avg >= 80) printf("Grade : E\n", avg / cnt);
28+
else if (avg >= 70) printf("Grade : A\n", avg / cnt);
29+
else if (avg >= 55) printf("Grade : P\n", avg / cnt);
30+
else if (avg >= 40) printf("Grade : D\n", avg / cnt);
31+
else printf("Grade : T\n", avg / cnt);
32+
33+
}

12 - Inheritance/Solution.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
class Person {
7+
protected:
8+
string firstName;
9+
string lastName;
10+
int id;
11+
public:
12+
Person(string firstName, string lastName, int identification) {
13+
this->firstName = firstName;
14+
this->lastName = lastName;
15+
this->id = identification;
16+
}
17+
//Aditya Seth
18+
19+
void printPerson() {
20+
cout << "Name: " << lastName << ", " << firstName << "\nID: " << id << "\n";
21+
}
22+
23+
};
24+
25+
class Student : public Person {
26+
private:
27+
vector<int> testScores;
28+
public:
29+
30+
Student(string firstName, string lastName, int id, vector<int> scores) : Person(firstName, lastName, id) {
31+
this->testScores = scores;
32+
}
33+
34+
35+
char calculate() {
36+
int total = 0;
37+
38+
for (int i = 0; i < this->testScores.size(); i++)
39+
total += this->testScores[i];
40+
41+
int avg = (int) (total / testScores.size());
42+
43+
if (avg >= 90 && avg <= 100) return 'O';
44+
if (avg >= 80 && avg < 90) return 'E';
45+
if (avg >= 70 && avg < 80) return 'A';
46+
if (avg >= 55 && avg < 70) return 'P';
47+
if (avg >= 40 && avg < 55) return 'D';
48+
return 'T';
49+
}
50+
};
51+
52+
int main() {
53+
string firstName;
54+
string lastName;
55+
int id;
56+
int numScores;
57+
cin >> firstName >> lastName >> id >> numScores;
58+
vector<int> scores;
59+
for (int i = 0; i < numScores; i++) {
60+
int tmpScore;
61+
cin >> tmpScore;
62+
scores.push_back(tmpScore);
63+
}
64+
Student *s = new Student(firstName, lastName, id, scores);
65+
s->printPerson();
66+
cout << "Grade: " << s->calculate() << "\n";
67+
return 0;
68+
}

12 - Inheritance/Solution.kt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.util.Scanner
2+
3+
open class Person(var firstName: String, var lastName: String, var idNumber: Int) {
4+
fun printPerson() {
5+
println("Name: $lastName, $firstName\nID: $idNumber")
6+
}
7+
}
8+
9+
class Student(firstName: String, lastName: String, identification: Int, private val testScores: IntArray) :
10+
Person(firstName, lastName, identification) {
11+
12+
fun calculate(): Char {
13+
var total = 0
14+
15+
for (testScore in testScores) total += testScore
16+
17+
val avg = total / testScores.size
18+
19+
if (avg in 90..100) return 'O'
20+
if (avg in 80..89) return 'E'
21+
if (avg in 70..79) return 'A'
22+
if (avg in 55..69) return 'P'
23+
return if (avg in 40..54) 'D' else 'T'
24+
}
25+
}
26+
27+
fun main(args: Array<String>) {
28+
val scan = Scanner(System.`in`)
29+
val firstName = scan.next()
30+
val lastName = scan.next()
31+
val id = scan.nextInt()
32+
val numScores = scan.nextInt()
33+
val testScores = IntArray(numScores)
34+
for (i in 0 until numScores) {
35+
testScores[i] = scan.nextInt()
36+
}
37+
scan.close()
38+
39+
val s = Student(firstName, lastName, id, testScores)
40+
s.printPerson()
41+
println("Grade: " + s.calculate())
42+
}

12 - Inheritance/Solution.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Person:
2+
def __init__(self, firstName, lastName, idNumber):
3+
self.firstName = firstName
4+
self.lastName = lastName
5+
self.idNumber = idNumber
6+
7+
def printPerson(self):
8+
print("Name:", self.lastName + ",", self.firstName)
9+
print("ID:", self.idNumber)
10+
11+
#Aditya Seth
12+
class Student(Person):
13+
def __init__(self, firstName, lastName, idNumber, testScores):
14+
super().__init__(firstName, lastName, idNumber)
15+
self.testScores = testScores
16+
17+
def calculate(self):
18+
total = 0
19+
20+
for testScore in self.testScores:
21+
total += testScore
22+
23+
avg = total / len(self.testScores)
24+
25+
if 90 <= avg <= 100:
26+
return 'O'
27+
if 80 <= avg < 90:
28+
return 'E'
29+
if 70 <= avg < 80:
30+
return 'A'
31+
if 55 <= avg < 70:
32+
return 'P'
33+
if 40 <= avg < 55:
34+
return 'D'
35+
return 'T'
36+
37+
38+
line = input().split()
39+
firstName = line[0]
40+
lastName = line[1]
41+
idNum = line[2]
42+
numScores = int(input())
43+
scores = list(map(int, input().split()))
44+
s = Student(firstName, lastName, idNum, scores)
45+
s.printPerson()
46+
print("Grade:", s.calculate())

12 - Inheritance/Solution.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class Person
2+
def initialize(firstName, lastName, id)
3+
@firstName = firstName
4+
@lastName = lastName
5+
@id = id
6+
end
7+
8+
def printPerson()
9+
print("Name: ",@lastName , ", " + @firstName ,"\nID: " , @id)
10+
end
11+
end
12+
13+
class Student < Person
14+
def initialize(firstName, lastName, id, scores)
15+
super(firstName, lastName, id)
16+
@scores = scores
17+
end
18+
19+
def calculate
20+
sum = 0
21+
@scores.each do |score|
22+
sum = sum + score
23+
end
24+
25+
average = sum / @scores.length
26+
27+
if(average >= 90)
28+
return 'O' # Outstanding
29+
elsif(average >= 80)
30+
return 'E' # Exceeds Expectations
31+
elsif(average >= 70)
32+
return 'A' # Acceptable
33+
elsif(average >= 55)
34+
return 'P' # Poor
35+
elsif(average >= 40)
36+
return 'D' # Dreadful
37+
else
38+
return 'T' # Troll
39+
end
40+
end
41+
end
42+
43+
input = gets.split()
44+
firstName = input[0]
45+
lastName = input[1]
46+
id = input[2].to_i
47+
numScores = gets.to_i
48+
scores = gets.strip().split().map!(&:to_i)
49+
s = Student.new(firstName, lastName, id, scores)
50+
s.printPerson
51+
print("\nGrade: " + s.calculate)

0 commit comments

Comments
 (0)