Skip to content

h4sski_code #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
node_modules
.tmp
npm-debug.log

# My addition
*src/Ch*.exe
*src/Ch*.out
*src/Ch*.app
*src/Ch*.
8 changes: 8 additions & 0 deletions src/Ch01/01_02b/CodeDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Learning C++
// Exercise 01_02
// Hello World, by Eduardo Corpeño

#include <iostream>

int main(){
std::cout << "Hi there!" << std::endl;
std::cout << std::endl << std::endl;
return (0);
}
3 changes: 2 additions & 1 deletion src/Ch01/01_03/CodeDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

int main(){
std::string str;
std::cout << "Tell me, what is your name: ";
std::cin >> str;
std::cout << str;
std::cout << "Nice to meet you, " << str << "!";

std::cout << std::endl << std::endl;
return (0);
Expand Down
3 changes: 3 additions & 0 deletions src/Ch02/02_13/CodeDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
int main(){
int nums[5] = {1,23,32,24,337};
float result;
int sum;

// Write your code here
sum = nums[0] + nums[1] + nums[2] + nums[3] + nums[4];
result = sum / 5.0f;

std::cout << "The average is " << result << std::endl;

Expand Down
44 changes: 43 additions & 1 deletion src/Ch03/03_11/records.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
// Write your implementation code here
// Write your implementation code here
#include "records.h"

Student::Student(int the_id, std::string the_name){
id = the_id;
name = the_name;
};
int Student::get_id() const{
return id;
};
std::string Student::get_name() const{
return name;
};

Course::Course(int the_id, std::string the_name, unsigned char the_credits){
id = the_id;
name = the_name;
credits = the_credits;
};
int Course::get_id() const{
return id;
};
std::string Course::get_name() const{
return name;
};
int Course::get_credits() const{
return credits;
};

Grade::Grade(int the_sid, int the_cid, char the_grd) {
student_id = the_sid;
course_id = the_cid;
grade = the_grd;
};
int Grade::get_student_id() const{
return student_id;
};
int Grade::get_course_id() const{
return course_id;
};
char Grade::get_grade() const{
return grade;
};
32 changes: 31 additions & 1 deletion src/Ch04/04_05/CodeDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
int main(){
float GPA = 0.0f;
int id;
int total_credits = 0;

std::vector<Student> students = {Student(1, "George P. Burdell"),
Student(2, "Nancy Rhodes")};
Expand All @@ -26,9 +27,38 @@ int main(){

// Calculate the GPA for the selected student.
// Write your code here
for (Grade& grade : grades){
if (grade.get_student_id() == id){
int credit = 0;
for (auto course : courses){
if (grade.get_course_id() == course.get_id())
credit = course.get_credits();
};
total_credits += credit;
switch (grade.get_grade()){
case 'A':
GPA += 4*credit;
break;
case 'B':
GPA += 3*credit;
break;
case 'C':
GPA += 2*credit;
break;
case 'D':
GPA += 1*credit;
break;
default:
GPA += 0*credit;
break;
};
};
};

GPA /= total_credits;

std::string student_str;
student_str = students[0].get_name(); // Change this to the selected student's name
student_str = students[id-1].get_name(); // Change this to the selected student's name

std::cout << "The GPA for " << student_str << " is " << GPA << std::endl;

Expand Down