SOLVED CS411 Assignment 1 Solution and Discussion
-
Visual Programing (CS411)
Assignment#01 (GRADED)
Total marks = 20
Deadline Date = 18-11-2019Please 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. - operator
-
100% Solved:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Student { public int x; public Student() { } public Student(int i) { x = i; // y = j; } /* public void Showsum() private int sum1 = x + y; { Console.WriteLine(sum1); }*/ public static Student operator +(Student ss, Student ss2) { Student temp = new Student(); temp.x = Int32.Parse(ss.x.ToString() + ss2.x.ToString()); return temp; // return temp = tostring(d1) + tostring(d2); } public static Student operator * (Student ss, Student ss2) { double d= (double)ss.x; double dd = (double)ss2.x; Student temp = new Student(); double result= Math.Pow( d ,dd); temp.x =(int) result; return temp; // return temp = tostring(d1) + tostring(d2); } class Program { static void Main(string[] args) { Student s1 = new Student(2); //S1.Showsum(); // displays 15 Student s2 = new Student(4); Student s3 = s1 + s2; Console.WriteLine(s3.x.ToString()); Student s4 = s1 * s2; Console.WriteLine(s4.x.ToString()); Console.Read(); //S2. } } } }
-
100% Solved:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Student { public int x; public Student() { } public Student(int i) { x = i; // y = j; } /* public void Showsum() private int sum1 = x + y; { Console.WriteLine(sum1); }*/ public static Student operator +(Student ss, Student ss2) { Student temp = new Student(); temp.x = Int32.Parse(ss.x.ToString() + ss2.x.ToString()); return temp; // return temp = tostring(d1) + tostring(d2); } public static Student operator * (Student ss, Student ss2) { double d= (double)ss.x; double dd = (double)ss2.x; Student temp = new Student(); double result= Math.Pow( d ,dd); temp.x =(int) result; return temp; // return temp = tostring(d1) + tostring(d2); } class Program { static void Main(string[] args) { Student s1 = new Student(2); //S1.Showsum(); // displays 15 Student s2 = new Student(4); Student s3 = s1 + s2; Console.WriteLine(s3.x.ToString()); Student s4 = s1 * s2; Console.WriteLine(s4.x.ToString()); Console.Read(); //S2. } } } }
-
@zaasmi
Solution file attached please check
bc12345678.cs//<> // 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(); } } }
-
@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.
-
-
-
@zareen said in CS411 Assignment 1 Solution and Discussion:
You are required to create a C# application Console using Visual Studio.


100% Off on Your FEE Join US! Ask Me How?


