100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1512 Assignment 3 2024 memo R99,33
Add to cart

Other

COS1512 Assignment 3 2024 memo

2 reviews
 43 views  3 purchases

COS1512 Assignment 3 2024 memo

Preview 2 out of 14  pages

  • August 11, 2024
  • 14
  • 2024/2025
  • Other
  • Unknown
All documents for this subject (45)

2  reviews

review-writer-avatar

By: khulisomulima • 3 months ago

review-writer-avatar

By: sabrinaerasmus • 3 months ago

avatar-seller
foxNotes
Question 1
#include <iostream>
#include <string>
using namespace std;

class Student {
private:
string name;
int quiz1;
int quiz2;
int midtermExam;
int finalExam;

public:
Student() : name(""), quiz1(0), quiz2(0), midtermExam(0),
finalExam(0) {}

void setName(string n) { name = n; }
void setQuiz1(int q) { quiz1 = q; }
void setQuiz2(int q) { quiz2 = q; }
void setMidtermExam(int m) { midtermExam = m; }
void setFinalExam(int f) { finalExam = f; }

string getName() { return name; }
int getQuiz1() { return quiz1; }
int getQuiz2() { return quiz2; }
int getMidtermExam() { return midtermExam; }
int getFinalExam() { return finalExam; }

double calculateAverage() {
double quizAverage = (quiz1*10 + quiz2*10) / 2.0;
return 0.5 * finalExam + 0.25 * midtermExam + 0.25 *
quizAverage;
}
};

int main() {
Student student;
cout << "Enter student name: ";
string name;
getline(cin, name);
student.setName(name);

cout << "Enter quiz 1 score: ";
int quiz1;
cin >> quiz1;
student.setQuiz1(quiz1);

cout << "Enter quiz 2 score: ";
int quiz2;
cin >> quiz2;

, student.setQuiz2(quiz2);

cout << "Enter midterm exam score: ";
int midtermExam;
cin >> midtermExam;
student.setMidtermExam(midtermExam);

cout << "Enter final exam score: ";
int finalExam;
cin >> finalExam;
student.setFinalExam(finalExam);

cout << "Student record for: " << student.getName() << endl;
cout << "Quiz 1: " << student.getQuiz1() << endl;
cout << "Quiz 2: " << student.getQuiz2() << endl;
cout << "Midterm exam: " << student.getMidtermExam() << endl;
cout << "Final exam: " << student.getFinalExam() << endl;
cout << "Average: " << student.calculateAverage() << endl;

return 0;
}




Question 2
(a) The purpose of the keywords public and private in the class
declaration is to define access levels for the class members.
Public members can be accessed from anywhere, while private
members can only be accessed within the class itself or by friends
of the class.

(b) A class is a blueprint or a template that defines the
properties and behavior of an object. An object, on the other
hand, is an instance of a class, which has its own set of
attributes (data) and methods (functions).

(c) To "instantiate" an object means to create an instance of a
class.

(d) The purpose of a constructor is to initialize objects when
they are created. It is a special member function that is called
when an object is instantiated.

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller foxNotes. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R99,33. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53022 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R99,33  3x  sold
  • (2)
Add to cart
Added