Search This Blog

Saturday, 21 July 2018

CS201 Introduction to Programming - Sollution og Assignment 3

#include <iostream>
#include <string>
using namespace std;
class Laptop
{
    private:
        string Brand, Processor;
        int Ram, hardDrive;
   
    public:
    Laptop()
        {
            cout<<"Default Constructor Called \n";
            Brand = "None";
            Processor = "None";
            Ram = 0;
            hardDrive = 0;
        }
   
        void setBrand(string b)
        { Brand = b; }
        void setProcessor(string p)
        { Processor = p; }
        void setRam(int r)
        { Ram = r; }
        void sethD(int hd)
        { hardDrive = hd; }
   
        string getBrand()
        { return Brand; }
        string getProcessor()
        { return Processor; }
        int getRam()
        { return Ram; }
        int gethD()
        { return hardDrive; }
   
    Laptop(string theBrand, string theProcessor, int theRam, int thehardDrive)
        {
          cout<<"Parameterized Constructor Called...\n";
          Brand = theBrand;
          Processor = theProcessor;
          Ram =  theRam;
          hardDrive = thehardDrive;
        }
    };
int main()
{
 
  Laptop l;
  cout<<"\nBrand : "<<l.getBrand()<<"\nProcessor : "<<l.getProcessor()<<"\nRam : "<<l.getRam()<<"\nHard Drive : "<<l.gethD()<<"\n\n";


  Laptop l2("dell", "i5", 400, 500);
  cout<<"\nBrand : "<<l2.getBrand()<<"\nProcessor : "<<l2.getProcessor()<<"\nRam : "<<l2.getRam()<<"\nHard Drive : "<<l2.gethD()<<"\n";
  system("pause");
}

No comments:

Post a Comment