CS411 Assignment 1 Solution and Discussion


  • Cyberian's Gold

    Visual Programing (CS411)
    Assignment#01 (GRADED)
    Total marks = 20
    Deadline Date = 18-11-2019

    Please read all the instructions carefully before attempting the assignment.
    You are required to create a C# application Console using Visual Studio.
    Problem Statement:
    You will declare a new class name as “Student” then you will perform the Operator Overloading for following binary operators:

    • operator
      *operator:
      For this you will take
      Second last digits and the last digit of your VU id as input.
      For example, if your VU id is bc12345678 you will take 7 and 8.
      You will write then following functions in class “student:
      For + operator overloading 1st function: concatenate last two digits
      Example: Your id is BC12345678
      1st function 7+8=78
      For * operator overloading 2nd function: take power of 2nd last digit the times last digit is
      Example: your ID is BC12345678
      2nd function 78=5,764,801
      Note: Program must show your own VUID usage.

    Submission details
    Following Files Must be submitted in a single zip or rar file.
    • .C# code file (file name should be your VUID)
    • A .gif file which shows working of your Application (For Recording .gif a software named Screentogif is uploaded on LMS, or you can use any other gif recording tool as well)
    You are not required to submit the complete project, only copy these three files from project folder. Please note if you submit doc file you will be awarded 0 marks.
    If you do not submit any of the above-mentioned file you will be awarded 0 Marks.


  • Cyberian's Gold

    Solution file attached please check
    bc12345678.cs


  • Cyberian's Gold

    @zaasmi

    
    
        //<>
        //
    
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
    
        namespace cs411
        {
        //my student id is bc150401804
        //last two digits of my student id are 0 and 4
    
        public class Student
        {
    
        public int Number { get; set; }
        public Student(int number)
        {
        Number = number;
        }
    
        public Student()
        {
    
        }
    
        public static string operator +(Student left, Student right)
        {
        string result = left.Number.ToString() + right.Number.ToString();
        return result;
        }
    
        public static long operator *(Student left, Student right)
        {
    
        int @base = left.Number;
        int power = right.Number;
    
        long result = 1;
    
        for (int i = 1; i <= power; i++)
        {
        result*= @base;
        }
    
    
        return result;
        }
    
    
        }
    
        class Program
        {
        static void Main(string[] args)
        {
    
        var leftStudent = new Student(number:0); //first number of last two digits
        var rightStudent = new Student(number: 4); //second number of last two digits
    
        var firstResult = leftStudent + rightStudent;
        var secondResult = leftStudent * rightStudent;
    
        Console.WriteLine("1st operator + overloading result is = " + firstResult);
        Console.WriteLine("2nd operator * overloading result is = " + secondResult);
    
        Console.ReadKey();
        }
        }
        }
    
    

  • Cyberian's Gold

    @zareen said in CS411 Assignment 1 Solution and Discussion:

    operator
    *operator:
    For this you will take
    Second last digits and the last digit of your VU id as input.
    For example, if your VU id is bc12345678 you will take 7 and 8.
    You will write then following functions in class “student:
    For + operator overloading 1st function: concatenate last two digits
    Example: Your id is BC12345678
    1st function 7+8=78
    For * operator overloading 2nd function: take power of 2nd last digit the times last digit is
    Example: your ID is BC12345678
    2nd function 78=5,764,801
    Note: Program must show your own VUID usage.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace cs411
    {
    class Program
    {
    static void Main(string[] args)
    {
    //for sum
    Student std1 = new Student();
    Student std2 = new Student();
    Student std3 = new Student();
    
    // for *
    Student std4 = new Student();
    Student std5 = new Student();
    Student std6 = new Student();
    
    std3 = std1 + std2;
    std6 = std4 * std5;
    
    //Printing Sum
    Console.WriteLine("Overloading + Operator Result {0}", std3.concat);
    
    
    //printing Power
    Console.WriteLine("Overloading * Operator Result {0}", std6.raiseToPower);
    
    Console.ReadKey();
    }
    
    }
    
    class Student
    {
    public int secondLast = 7;
    public int Last = 8;
    public String concat = null;
    
    public double raiseToPower = 0;
    
    
    public Student() {
    
    secondLast = 7;
    Last = 8;
    }
    
    public static Student operator *(Student s1, Student s2)
    {
    Student s3 = new Student();
    s3.raiseToPower = Math.Pow(s1.secondLast, s2.Last);
    return s3;
    }
    
    public static Student operator +(Student s1, Student s2)
    {
    Student s3 = new Student();
    s3.concat= s1.secondLast.ToString() +s2.Last.ToString();
    return s3;
    }
    
    
    }
    }
    
    // just copy paste the code in your program. 
    

  • Cyberian's Gold


  • Cyberian's Gold


  • Cyberian's Gold

    @zareen said in CS411 Assignment 1 Solution and Discussion:

    You are required to create a C# application Console using Visual Studio.



    Recent Topics


  • 11
  • 6
  • 1
  • 7
  • 3
  • 1
  • 2
  • 2
|