Hello, I have answered this question before. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#include<iostream>
using namespace std;
class Course{
private:
//private attributes
string name;
int numStudents;
string* students;
int capacity;
public:
//constructor taking course name and capacity
Course(string &courseName, int _capacity){
name=courseName;
capacity=_capacity;
//initializing dynamic array
students=new string[capacity];
numStudents=0;
}
//destructor
~Course(){
//deallocating dynamic array. square brackets needs to be used here
delete[] students;
}
//returns the course name
string getCourseName(){
return name;
}
//returns the number of students
int getNumberOfStudents(){
return numStudents;
}
//method to add a student to the students array
void addStudent(string stud_name){
//checking if array is full
if(numStudents==capacity){
//updating capacity
capacity=capacity+5;
//creating a new dynamic array of new capacity
string* newArray=new string[capacity];
//copying all values from students to new array
for(int i=0;i<numStudents;i++){
*(newArray+i)=*(students+i);
}
//deleting old array, replacing with new one
delete[] students;
students=newArray;
//displaying a message
cout<<"Class size has been expanded to " << capacity << endl;
}
//adding new student at the end of the array
*(students+numStudents)=stud_name;
numStudents++;
}
//method to print all students
void printStudents(){
cout<<"Following students are opted for this course."<<endl;
//looping and printing all students
for(int i=0;i<numStudents;i++){
cout<<*(students+i)<<endl;
}
}
};
int main(){
//creating a course and adding 5 students
string courseName="CS123";
Course course(courseName,3);
course.addStudent("Oliver Queen");
course.addStudent("Felicity Smoak");
course.addStudent("John Diggle");
course.addStudent("Curtis");
course.addStudent("Dinah");
//displaying details
cout<<"Course Name: "<<course.getCourseName()<<endl;
cout<<"Number of students: "<<course.getNumberOfStudents()<<endl;
course.printStudents();
return 0;
}
/*OUTPUT*/
Class size has been expanded to 8
Course Name: CS123
Number of students: 5
Following students are opted for this course.
Oliver Queen
Felicity Smoak
John Diggle
Curtis
Dinah
Write a C++ console program that defines a class named Course that utilizes a dynamically allocated...
Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course { private String courseName; private String[] students = new...
I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...
Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...
Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). ○ A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. ○ The relevant get and set methods for the data fields. ○ A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) ● Create a new ArrayList called courses1, add 5 courses to...
Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...
Assuming the following class declaration: class Course { private: string grade_; int units_; public: Course ( ); Course ( string grade, int units); ~Course ( ); string get_grade ( ) const ; int get_units ( ) const; }; NOTE: Class definitions are not provided but you may assume they're properly defined. Variable names used in your answers must follow our stated naming convention especially for pointer names. Write a fragment of...
In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...
Create a C++ console program that defines a class named EvenNumber that represents an even number. Create the class inside a separate header file (.h) and then include this header in your main source code file. The class should have one private integer data field to store the even number. The default constructor should initialize the data field to 0. Also define a 1-arg constructor that initializes the object with the specified value. Define a public getter method named getValue...
2. Write a program named lab3 2.app that contains a class named Student to store student information Information that will be relevant to store is first name, last name, id number, GPA, and major (1) Define a member function named set0, which allows you to set all member variables. This function has an empty parameter list, and its return type is void. So, within the function you'll prompt for information. Note: For entering major, if you need a space, use...
Given a class called Student and a class called Course that
contains an ArrayList of Student. Write a method called
getDeansList() as described below. Refer to Student.java below to
learn what methods are available.
I will paste both of the simple .JAVA codes below
COURSE.JAVA
import java.util.*;
import java.io.*;
/******************************************************
* A list of students in a course
*****************************************************/
public class Course{
/** collection of Students */
private ArrayList<Student> roster;
/*****************************************************
Constructor for objects of class Course
*****************************************************/...