answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
konstantin123 [22]
2 years ago
14

Define a Course base class with attributes number and title. Define a print_info() method that displays the course number and ti

tle.
Also define a derived class OfferedCourse with the additional attributes instructor_name, term, and class_time.
Ex: If the input is:
ECE287
Digital Systems Design
ECE387
Embedded Systems Design
Mark Patterson
Fall 2018
WF: 2-3:30 pm
the output is:
Course Information:
Course Number: ECE287
Course Title: Digital Systems Design
Course Information:
Course Number: ECE387
Course Title: Embedded Systems Design
Instructor Name: Mark Patterson
Term: Fall 2018 Class
Time: WF: 2-3:30 pm

Computers and Technology
1 answer:
lesya [120]2 years ago
7 0

Answer:

Here is the Python program:

class Course:

   def __init__(self,number, title):

       self.number = number

       self.title = title

   def print_info(self):

       print("Course Information:")  

       print("Course Number:", self.number)

       print("Course Title:", self.title)

class OfferedCourse(Course):

   def __init__(self, number, title,instructor_name,term,class_time):

       self.number = number

       self.title = title

       self.instructor_name = instructor_name

       self.term = term

       self.class_time=class_time

if __name__ == "__main__":

   course_number = input()

   course_title = input()

   o_course_number = input()

   o_course_title = input()

   instructor_name = input()

   term = input()

   class_time = input()

   my_course = Course(course_number, course_title)

   my_course.print_info()

   my_offered_course = OfferedCourse(o_course_number, o_course_title, instructor_name, term, class_time)

   my_offered_course.print_info()

   print('Instructor Name:', my_offered_course.instructor_name)

   print('Term:', my_offered_course.term)

   print('Class Time:', my_offered_course.class_time)

Explanation:

Course is a base class with attributes number and title. It has a print_info() method that displays the course number and title.

self keyword is the keyword which is used to easily access all the instances defined within a Course class, including its method and attributes number and title.

__init__ is a constructor which is called when an instance is created from the Course, and access is required to initialize the attributes number and title of Course class.

OfferedCourse is a class which is derived from base class Course. In addition to attributes number and title, it has attributes attributes instructor_name, term, and class_time.

A special attribute __name__. The value of __name__ attribute is set to “__main__” in order to run this module as a main program. In this main program input() method is used to take input from user. The input is the course number, title, instructor name, term and class time. The object my_course of Course class is created and the constructor of Course class is called passing the course_number and course_title using this object to access the attributes (member variables number and term) of the Course class. Next the instance my_course is used to call function print_info() of Course class.

The object my_offered_course of OfferedCourse class is created and the constructor of OfferedCourse class is called passing the o_course_number, o_course_title, instructor_name, term, class_time using this object to access the attributes number, title, instructor_name,term, class_time OfferedCourse class. Next the instance my_offered_course is used to call function print_info() of Course class. Here it is to be noticed that the derived class OfferedCourse uses the method print_info() of its base class Course. Last three print statements of the main program use object my_offered_course to access the attributes  instructor_name, term and class_time of class OfferedCourse to display the their values.

The screenshot of the program output is attached.

You might be interested in
The piston engine uses the ________ to convert the reciprocating motion of the piston into rotary motion.
PSYCHO15rus [73]

The piston engine uses the crankshaft to convert the reciprocating motion of the piston into rotary motion.

<span>The crankshaft is used to convert reciprocating motion of the piston into rotary motion, while the conversion process is called torque, which is a twisting force. Aside from crankshaft, there are a total of four parts of the engine that work together in order to convert the reciprocating motion into rotary motion namely cylinder, or also called the chamber of the piston, the piston itself, and the connecting rod.</span>

5 0
2 years ago
Write a copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *thi
ollegr [7]

Answer:

Here is the copy assignment operator for CarCounter:

CarCounter& CarCounter::operator=(const CarCounter& objToCopy) {

carCount = objToCopy.carCount;

return *this;  }

The syntax for copy assignment operator is:

ClassName& ClassName :: operator= ( ClassName& object_name)

In the above chunk of code class name Is CarCounter and object name is objToCopy.

Assignment operator = is called which assigns objToCopy.carCount to the new objects's carCount.

This operator basically is called when an object which is already initialized is assigned a new value from another current object.

Then return *this returns the reference to the calling object

Explanation:

The complete program is:

#include <iostream>  //to use input output functions

using namespace std;   //to access objects like cin cout

class CarCounter {  //class name

public:  // public member functions of class CarCounter

CarCounter();  //constructor of CarCounter

CarCounter& operator=(const CarCounter& objToCopy);  //copy assignment operator for CarCounter

void SetCarCount(const int setVal) {  //mutator method to set the car count value

carCount = setVal;  } //set carCount so setVal

int GetCarCount() const {  //accessor method to get carCount

return carCount;  }  

private:  //private data member of class

int carCount;  };    // private data field of CarCounter

CarCounter::CarCounter() {  //constructor

carCount = 0;  //intializes the value of carCount in constructor

return; }  

// FIXME write copy assignment operator  

CarCounter& CarCounter::operator=(const CarCounter& objToCopy){

/* copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *this */

carCount = objToCopy.carCount;

return *this;}  

int main() {  //start of main() function

CarCounter frontParkingLot;  // creates CarCounter object

CarCounter backParkingLot;   // creates CarCounter object

frontParkingLot.SetCarCount(12);  // calls SetCarCount method using object frontParkingLot to set the value of carCount to 12

backParkingLot = frontParkingLot;  //assigns value of frontParkingLot to backParkingLot

cout << "Cars counted: " << backParkingLot.GetCarCount();  //calls accessor GetCarCount method to get the value of carCount and display it in output

return 0;  }

The output of this program is:

Cars counted = 12

3 0
2 years ago
OH GOD PLEASE HELP I CAN'T FIGURE THIS OUT-
Angelina_Jolie [31]

Answer:

what does that even mean like what is the problem in the question

5 0
2 years ago
Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following string
Artist 52 [7]

Answer:

#include <bits/stdc++.h>

using namespace std;

bool isPalindrome(string str)

{

   char a,b;

int length = str.length();

for (int i = 0; i < length / 2; i++)

{

   a=tolower(str[i]);//Converting both first characters to lowercase..

   b=tolower(str[length-1-i]);

   if (b != a )

return false;

}

return true;

   

}

int main() {

   string t1;

   cin>>t1;

   if(isPalindrome(t1))

   cout<<"The string is Palindrome"<<endl;

   else

   cout<<"The string is not Palindrome"<<endl;

return 0;

}

Output:-

Enter the string

madam

The string is Palindrome

Enter the string

abba

The string is Palindrome

Enter the string

22

The string is Palindrome

Enter the string

67876

The string is Palindrome

Enter the string

444244

The string is not Palindrome

Explanation:

To ignore the cases of uppercase and lower case i have converted every character to lowercase then checking each character.You can convert to uppercase also that will also work.

6 0
2 years ago
Suggest how the following requirements might be rewritten in a quantitative way. You may use any metrics you like to express the
kotegsom [21]

Answer:

Did you get the answer yet or not or should i sent it?

Explanation:

3 0
2 years ago
Other questions:
  • In Python, what kind of error is returned by the following code? (e.g. NameError, ValueError, IOError, etc.) def my_func(n1, n2)
    8·1 answer
  • Write a class called Counter that represents a simple tally counter, which might be used to count people as they enter a room. T
    9·1 answer
  • In the game of $Mindmaster$, secret codes are created by placing pegs of any of seven different colors into four slots. Colors m
    5·1 answer
  • What technology gets its name from the notion that it ignores the traditional A, B, and C class designations for IP addresses?
    14·1 answer
  • Alyosha was explaining to a friend the importance of protecting a cryptographic key from cryptoanalysis. He said that the key sh
    10·1 answer
  • Information in​ folders, messages,​ memos, proposals,​ emails, graphics, electronic slide​ presentations, and even videos create
    7·1 answer
  • Write the definition of a function power_to, which receives two parameters. The first is a float and the second is an integer. T
    5·1 answer
  • Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number w
    14·1 answer
  • When should a developer begin thinking about scalability? 1 during the design phase 2during testing 3when traffic increases by 2
    14·1 answer
  • The Coins class was created to hold all your loose change, kind of like a piggy bank! For this exercise, you are going to simula
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!