diff --git a/.gitignore b/.gitignore index 4b64bc3c..eb96b2ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ node_modules .tmp npm-debug.log + +# My addition +*src/Ch*.exe +*src/Ch*.out +*src/Ch*.app +*src/Ch*. \ No newline at end of file diff --git a/src/Ch01/01_02b/CodeDemo.cpp b/src/Ch01/01_02b/CodeDemo.cpp index c4989f70..b07f36b3 100644 --- a/src/Ch01/01_02b/CodeDemo.cpp +++ b/src/Ch01/01_02b/CodeDemo.cpp @@ -1,3 +1,11 @@ // Learning C++ // Exercise 01_02 // Hello World, by Eduardo CorpeƱo + +#include + +int main(){ + std::cout << "Hi there!" << std::endl; + std::cout << std::endl << std::endl; + return (0); +} \ No newline at end of file diff --git a/src/Ch01/01_03/CodeDemo.cpp b/src/Ch01/01_03/CodeDemo.cpp index 2a89889d..5c7d91df 100644 --- a/src/Ch01/01_03/CodeDemo.cpp +++ b/src/Ch01/01_03/CodeDemo.cpp @@ -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); diff --git a/src/Ch02/02_13/CodeDemo.cpp b/src/Ch02/02_13/CodeDemo.cpp index 67b9459b..aa7f728d 100644 --- a/src/Ch02/02_13/CodeDemo.cpp +++ b/src/Ch02/02_13/CodeDemo.cpp @@ -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; diff --git a/src/Ch03/03_11/records.cpp b/src/Ch03/03_11/records.cpp index b55b5298..3fae3d1a 100644 --- a/src/Ch03/03_11/records.cpp +++ b/src/Ch03/03_11/records.cpp @@ -1 +1,43 @@ -// Write your implementation code here \ No newline at end of file +// 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; +}; \ No newline at end of file diff --git a/src/Ch04/04_05/CodeDemo.cpp b/src/Ch04/04_05/CodeDemo.cpp index 58e1c596..b474bf0e 100644 --- a/src/Ch04/04_05/CodeDemo.cpp +++ b/src/Ch04/04_05/CodeDemo.cpp @@ -9,6 +9,7 @@ int main(){ float GPA = 0.0f; int id; + int total_credits = 0; std::vector students = {Student(1, "George P. Burdell"), Student(2, "Nancy Rhodes")}; @@ -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;