100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4,6 TrustPilot
logo-home
Other

COS1512 Assignment 3 2024 memo

Rating
5,0
(2)
Sold
3
Pages
14
Uploaded on
11-08-2024
Written in
2024/2025

COS1512 Assignment 3 2024 memo










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
August 11, 2024
Number of pages
14
Written in
2024/2025
Type
Other
Person
Unknown

Subjects

Content preview

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.

Reviews from verified buyers

Showing all 2 reviews
1 year ago

1 year ago

5,0

2 reviews

5
2
4
0
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
foxNotes Acsess Business Academy
View profile
Follow You need to be logged in order to follow users or courses
Sold
112
Member since
2 year
Number of followers
63
Documents
35
Last sold
3 months ago
saveNotes

5,0

5 reviews

5
5
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions