Resource icon

CS304p Assignment 1 Solution Practical Assignment Spring 2023

kashif

Administrator
Staff member
VIP Member
Email Verified
kashif submitted a new resource:

CS304p Assignment 1 Solution Practical Assignment - VU CS304p Assignment 1 Solution Practical Assignment

This solution idea is for CS304p. You should read the whole document carefully and tally the method from your textbook/handout to get maximum numbers.

Rules for Assignments & GDBs:
It should be clear that your Assignments & GDBs will get no marks if:
  • It was submitted after the due date.
  • The submitted file does not open or the file is corrupt. (only for assignments)
  • Submitted solution is copied from another student or the internet.

Recommended:
-...

Read more about this resource...
 
CS304p Assignment 1 Solution Code Spring 2022
C++:
#include<iostream>
using namespace std;
class Complex{
  private:
  int real, image;
  public:
     Complex(){
       real  = 0;
       image = 0;     
     }
     Complex(Complex &obj)
     {
       real = obj.real;
       image = obj.image;
     }
     void get_data(){
       cout<<"Enter complex number:"<<endl;
       cout<<"real = ";
       cin>>real;
       cout<<"Imaginary = ";
       cin>>image;   
     }
           void display_data(){
      cout<<real<< " + "<<image<<"i"<<endl;
       }
       void add_Complex(Complex &obj);
       void sub_Complex(Complex &obj);   
};
int main(){
 
   Complex obj;
   obj.get_data();
   cout<<"1st Complex number is : "<<endl;
   obj.display_data();
   Complex obj1(obj);
   cout<<"2nd Complex number is : "<<endl;
   obj1.display_data();
   obj1.add_Complex(obj);
   obj1.sub_Complex(obj);
    
}
 
void Complex::add_Complex(Complex &obj){
  Complex temp;
  temp.real = real + obj.real;
  temp.image = image + obj.image;
  cout<<"Addition of complex number is : ";
  cout<<temp.real<<" + "<<temp.image<<"i"<<endl;
}

void Complex:: sub_Complex(Complex &obj){
    Complex temp;
  temp.real = real - obj.real;
  temp.image = image - obj.image;
  cout<<"Addition of complex number is : ";
  cout<<temp.real<<" - "<<temp.image<<"i"<<endl;
}
 
Top