Posts

Showing posts with the label Abstract

Go lang Tutorial. Abstraction Using Interface.

Image
Download

In C++, Compute Salary Of Full time Employee & Manager

Image
#include<iostream> using namespace std; class Employee{ protected: double baseSalary; int yearsOfService; public: Employee(double base, int years){ baseSalary = base; yearsOfService = years; } virtual double salary() = 0; }; class FulltimeEmployee : public Employee{ public: FulltimeEmployee(double base, int years): Employee(base, years){} double salary(){ double result = baseSalary; for(int year = 1; yearsOfService >= year; year++){ result += (result * 0.05); } return result; } }; class Manager: public FulltimeEmployee{ protected: int nosDirectReports; public: Manager(double base, int years, int reports): FulltimeEmployee(base, years){ nosDirectReports = reports; } double salary(){ double result = FulltimeEmployee::salary(); result += nosDirectReports * 0.1; return result; } }; int main(){ Employee *emp; emp = new FulltimeEmployee(300.0, 5); cout << "Fulltime Employee's salary: $...

How to find area & volume of different shapes with C#?

Image
using System; interface Shape{ double Area{get;} string Desc{get;} }; interface TwoDimensionalShape : Shape {} interface ThreeDimensionalShape : Shape { double Volume{get;} } class Circle: TwoDimensionalShape{ private double Radius; public Circle(double r){Radius = r;} public double Area{ get{ return ((Radius * Radius) * Math.PI); }} public string Desc{get{return "A circle";}} } class Square: TwoDimensionalShape{ private double Side; public Square(double s){Side = s;} public double Area{ get{ return (Side * Side); }} public string Desc{get{return "A square";}} } class Sphere: ThreeDimensionalShape{ private double Radius; public Sphere(double r){Radius = r;} public double Area{ get{ return (4 * Math.Pow(Radius,2) * Math.PI); }} public double Volume{ get{ return (4/3.0 * Math.Pow(Radius,3) * Math.PI); }} public string Desc{get{return "A sphere";}} } class Cube: ThreeDimensionalShape{ private double Side; public Cub...