Professional Documents
Culture Documents
Principle of Programming Practicals
Principle of Programming Practicals
//2D Array
class TwoDArr{
int td[][];
td[0][0]=9;
td[0][1]=8;
td[0][2]=7;
td[1][0]=6;
td[1][1]=5;
td[1][2]=4;
td[2][0]=30;
td[2][1]=2;
td[2][2]=1;
System.out.print(td[i][j] + "\t");
System.out.println();
}
Output: -
// 3D Array
class ThreeDArr {
int[][][] arr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } };
System.out.println("arr[" + i
+ "]["
+ j + "]["
+ z + "] = "
+ arr[i][j][z]);
Output: -
Implementation of Web Page in PHP
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<body>
</nav>
<section>
style="width:100%">
style="width:100%">
<img class="mySlides" src="img_band_chicago.jpg"
style="width:100%">
</section>
<p class="w3-justify">We have created a fictional band website. Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.</p>
</section>
<article class="w3-third">
<p>John</p>
</article>
<article class="w3-third">
<p>Paul</p>
<article class="w3-third">
<p>Ringo</p>
</article>
</section>
<p class="w3-medium">
</p>
</footer>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
x[i].style.display = "none";
myIndex++;
x[myIndex-1].style.display = "block";
setTimeout(carousel, 3000);
</script>
</body>
</html>
Screenshot: -
Implementation of pointers in C++
// array elements.
#include <stdio.h>
int main()
return 0;
Output: -
Implementation of Exception Handling in JAVA
class Eh{
int x=12;
int y=0;
System.out.println("statement 1");
try{
int z=x/y;
System.out.println(z);
catch(Exception e){
System.out.println("statement 2");
System.out.println("statement 3");
}
Output: -
Implementation of Parameter Passing Methods in C++
#include <iostream>
// function declaration
int main () {
int a = 100;
int b = 200;
swap(a, b);
return 0;
Output: -
#include <iostream>
// function declaration
int main () {
int a = 100;
int b = 200;
swap(a, b);
return 0;
Output: -
Implementation of Concurrent Execution using Threads
in JAVA
System.out.println("This is Thread1");
System.out.println("This is Thread2");
class UseThread{
t1.start();
t2.start();
}
Output: -
// Java code for thread creation by implementing the Runnable Interface
class UseRunnable{
t1.start();
t2.start();
}
Output: -
Implement Inheritance, Encapsulation & Polymorphism
in C#
Static Polymorphism:
Function Overloading
using System;
namespace PolymorphismApplication {
class Printdata {
void print(int i) {
void print(double f) {
void print(string s) {
p.print(5);
p.print(500.263);
Console.ReadKey();
Operator Overloading
using System;
namespace OperatorOvlApplication {
class Box {
length = len;
breadth = bre;
height = hei;
}
return box;
class Tester {
// box 1 specification
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.setHeight(5.0);
// box 2 specification
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.setHeight(10.0);
// volume of box 1
volume = Box1.getVolume();
// volume of box 2
volume = Box2.getVolume();
// volume of box 3
volume = Box3.getVolume();
Console.ReadKey();
Dynamic Polymorphism:
using System;
namespace PolymorphismApplication {
}
class Rectangle: Shape {
length = a;
width = b;
class RectangleTester {
double a = r.area();
Console.WriteLine("Area: {0}",a);
Console.ReadKey();
}
Using Virtual Functions
using System;
namespace PolymorphismApplication {
class Shape {
width = a;
height = b;
return 0;
class Caller {
int a;
a = sh.area();
class Tester {
c.CallArea(r);
c.CallArea(t);
Console.ReadKey();
}
Encapsulation :
using System;
namespace RectangleApplication {
class Rectangle {
//member variables
class ExecuteRectangle {
r.length = 4.5;
r.width = 3.5;
r.Display();
Console.ReadLine();
using System;
namespace RectangleApplication {
class Rectangle {
//member variables
length = Convert.ToDouble(Console.ReadLine());
width = Convert.ToDouble(Console.ReadLine());
class ExecuteRectangle {
r.Acceptdetails();
r.Display();
Console.ReadLine();
using System;
namespace RectangleApplication {
class Rectangle {
//member variables
class ExecuteRectangle {
r.length = 4.5;
r.width = 3.5;
r.Display();
Console.ReadLine();
}
Inheritance :
// concept of inheritance
using System;
namespace ConsoleApplication1 {
// Base class
class GFG {
// data members
this.name = name;
this.subject = subject;
public GeeksforGeeks()
{
Console.WriteLine("GeeksforGeeks");
// Driver class
class Sudo {
// Main Method
g.readers("Kirti", "C#");
}
Design of Lexical Analyzer using flex
//Decalring two counters one for number of lines other for number of characters
%{
int no_of_lines = 0;
int no_of_chars = 0;
%}
taking input***/
%%
\n ++no_of_lines;
. ++no_of_chars;
end return 0;
%%
int yywrap(){}
yylex();
no_of_lines, no_of_chars );
return 0;
}
Output: -
Working of Virtual Machine
Virtual machines allow you to run an operating system in an app window on your desktop that behaves
like a full, separate computer. You can use them play around with different operating systems, run
software your main operating system can’t, and try out apps in a safe, sandboxed environment.
There are several good free virtual machine (VM) apps out there, which makes setting up a virtual
machine something anybody can do. You’ll need to install a VM app, and have access to installation
media for the operating system you want to install.
In the VM world, the operating system actually running on your computer is called the host and any
operating systems running inside VMs are called guests. It helps keep things from getting too confusing.
In a particular VM, the guest OS is stored on a virtual hard drive—a big, multi-gigabyte file stored on
your real hard drive. The VM app presents this file the guest OS as a real hard drive. This means you
won’t have to mess around with partitioning or doing anything else complicated with your real hard
drive.
Virtualization does add some overhead, so don’t expect them to be as fast as if you had installed the
operating system on real hardware. Demanding games or other apps that require serious graphics and
CPU power don’t really do so well, so virtual machines aren’t the ideal way to play Windows PC games
on Linux or Mac OS X—at least, not unless those games are much older or aren’t graphically demanding.
The limit to how many VMs you can have are really just limited by the amount of hard drive space.
VMs also provide a way to run another OS’ software. For example, as a Linux or Mac user, you could
install Windows in a VM to run Windows apps you might not otherwise have access to. If you want to
run a later version of Windows—like Windows 10—but have older apps that only run on XP, you could
install Windows XP into a VM.
Another advantage VMs provide is that they are “sandboxed” from the rest of your system. Software
inside a VM can’t escape the VM to tamper with the rest of your system. This makes VMs a safe place to
test apps—or websites—you don’t trust and see what they do.
For example, when the “Hi, we’re from Windows” scammers came calling, we ran their software in a
VM to see what they would actually do—the VM prevented the scammers from accessing our
computer’s real operating system and files.
Sandboxing also allows you to run insecure OSes more safely. If you still need Windows XP for older
apps, you could run it in a VM where at least the harm of running an old, unsupported OS is mitigated.
VirtualBox: (Windows, Linux, Mac OS X): VirtualBox is very popular because it’s open-source and
completely free. There’s no paid version of VirtualBox, so you don’t have to deal with the usual
“upgrade to get more features” upsells and nags. VirtualBox works very well, particularly on
Windows and Linux where there’s less competition, making it a good place to start with VMs.
VMware Player: (Windows, Linux): VMware has their own line of virtual machine programs. You
can use VMware Player on Windows or Linux as a free, basic virtual machine tool. More
advanced features—many of which are found in VirtualBox for free—require upgrading to the
paid VMware Workstation program. We recommend starting out with VirtualBox, but if it
doesn’t work properly you may want to try VMware Player.
VMware Fusion: (Mac OS X): Mac users must buy VMware Fusion to use a VMware product,
since the free VMware Player isn’t available on a Mac. However, VMware Fusion is more
polished.
Parallels Desktop: (Mac OS X): Macs also have Parallels Desktop available. Both Parallels
Desktop and VMware Fusion for Mac are more polished than the virtual machine programs on
other platforms, since they’re marketed to average Mac users who might want to run Windows
software.
While VirtualBox works very well on Windows and Linux, Mac users may want to buy a more polished,
integrated Parallels Desktop or VMware Fusion program. Windows and Linux tools like VirtualBox and
VMware Player tend to be targeted to a geekier audience.
There are many more VM options, of course. Linux includes KVM, an integrated virtualization solution.
Professional and Enterprise version of Windows 8 and 10—but not Windows 7—include Microsoft’s
Hyper-V, another integrated virtual machine solution. These solutions can work well, but they don’t
have the most user-friendly interfaces.