CS508 Assignment No. 01 Solution and Discussion
-
Assignment No. 01 Semester Fall 2019
CS508- Modern Programming Languages Total Marks: 20Due Date: Tuesday, 12 November 2019.
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit if:
• The assignment is submitted after due date.
• The submitted assignment does not open or file is corrupt.
• The assignment is completely or partially copied from (other student or ditto copied from handouts or internet).
• Student ID is not mentioned in the assignment File or name of file is other than student ID.
• The assignment is not submitted in .doc or .docx format.
Uploading instructions
Your submission must include:
• Assignment should be in .doc or .docx format.
• Save your assignment with your ID (e.g. bx180200786.doc).
Assignment submission through email is NOT acceptable
Objective
The objective of this assignment is to learn how we can evaluate different programming languages based on syntax.
Note:
Your answer must follow the below given specifications.
• Font style: “Times New Roman”
• Font color: “Black”
• Font size: “12”
• Bold for heading only.
• Font in Italic is not allowed at all.
• Your answer should be precise and to the point, avoid irrelevant detail.Lectures Covered: This assignment covers Lecture # 01 – 07
Deadline
Your assignment must be uploaded/submitted at or before Tuesday, 12 November 2019.In this assignment we will evaluate 3 different languages on the basis of CPU time and Memory used for compilation.
3 languages we will be using are:
• Java
• C#
• C++
We will use nested loop which will execute finite number of times. For the sake of consistency, we will be using an online compiler of each language from the same website.
First you need to calculate the number of time both loops will run, for that we will use student id.
From the last 4 numbers of student id, first two characters will be number of times the outer loop will execute and last two characters will be number of times the inner loop will execute.
So, for example if student id is BC180201429 thenThe outer loop will execute 14 times and inner loop will execute 29 times.
Use the following compiler https://www.jdoodle.com/.-
Note down the CPU Time and memory Used for all the languages and fill the following table with CPU time memory and write the code for all 3 languages also take screen shots for each language and paste it in your solution file.
Language Code CPU Time Memory Used
-
You must write your student ID and language name in the code so it can be shown in the screen shot as attached below:
-
You are required to attach screen shots for all 3 languages showing output and resources used.
-
-
Solution:
Java:public class MyClass { public static void main(String args[]) { System.out.println("My id is BC180401429"); System.out.println("** Language is JAVA **"); for(int i=0;i<=14;i++){ for(int j=0;j<=29;j++){ System.out.print("Outer:"+i+"Inner:"+j); } } } }
C#:
using System; class Program { static void Main() { Console.WriteLine("My id is BC180401429"); Console.WriteLine("** Language is C# **"); for(int i=0;i<=14;i++){ for(int j=0;j<=29;j++){ Console.Write("Outer:"+i+"Inner:"+j); } } } }
C++:
#include <iostream> using namespace std; int main() { cout<< "My id is BC180401429 \n"; cout<< "** Language is C++ ** \n"; for(int i=0;i<=14;i++){ for(int j=0;j<=29;j++){ cout<< "Outer:"<<i<<"Inner:"<<j; } } }
-
Java:
public class MyClass { public static void main(String args[]) { System.out.println("My Student ID is BC160401656"); System.out.println("My Language is JAVA"); } }
C#:
using System; class Program { static void Main() { Console.Write("My Student is is BC160401656 \n"); Console.Write("My Language is C#"); } }
C++:
#include <iostream> using namespace std; int main() { cout"MY Student ID is BC160401656 \n " ; cout"Language is C++" ; }
-
-
Idea Solution
-
Correct Solution of C++
#include <iostream> using namespace std; int main() { int outerloop=1; int innerloop=1; cout<<"My Student ID is BS12345678\n"; cout<<"My coding Language is C++\n\n"; for(int i=1;i<=29;i++){ cout<<"outerloop:"<<outerloop++; if (outerloop == 30){ cout<<"\n.......\n"; for(int j=1;j<=79;j++){ cout<<"innerloop:"<<innerloop++; } } } }
-
public class MyClass { public static void main(String args[]){ System.out.println("My id is BS12345678"); System.out.println("My language is Java"); int outerloop=1; int innerloop=1; for(int i=1;i<=29;i++){ System.out.print("outerloop:" + outerloop++); if (outerloop == 30){ System.out.println("\n----------\n"); for(int j=1;j<=79;j++){ System.out.print("innerloop:" + innerloop++); } } } } }
-
using System; class Program { static void Main() { Console.Write("My Student is is BC160401656 \n"); Console.Write("My Language is C#"); int outerloop=1; int innerloop=1; for (int i=1;i<=29;i++){ Console.Write("outerloop:" + outerloop++); if (outerloop == 30){ Console.Write("\n----------\n"); for (int j=1;j<=79;j++){ Console.Write("ïnnerloop:" + innerloop++); } } } } }
-
Solution:
Java:public class MyClass { public static void main(String args[]) { System.out.println("My id is BC180401429"); System.out.println("** Language is JAVA **"); for(int i=0;i<=14;i++){ for(int j=0;j<=29;j++){ System.out.print("Outer:"+i+"Inner:"+j); } } } }
C#:
using System; class Program { static void Main() { Console.WriteLine("My id is BC180401429"); Console.WriteLine("** Language is C# **"); for(int i=0;i<=14;i++){ for(int j=0;j<=29;j++){ Console.Write("Outer:"+i+"Inner:"+j); } } } }
C++:
#include <iostream> using namespace std; int main() { cout<< "My id is BC180401429 \n"; cout<< "** Language is C++ ** \n"; for(int i=0;i<=14;i++){ for(int j=0;j<=29;j++){ cout<< "Outer:"<<i<<"Inner:"<<j; } } }