From f2b1d491956ad72165b1edfd0f1adcb95369065c Mon Sep 17 00:00:00 2001 From: Samiksha Upadhyay Date: Tue, 5 Oct 2021 10:11:55 +0530 Subject: [PATCH 1/4] Program to swap two numbers without using a third variable --- ...addfunction.cpp => sumofno_without_op_add.cpp} | 0 C++/swap_without_temp.txt | 15 +++++++++++++++ 2 files changed, 15 insertions(+) rename C++/{sumofno_without_operator&addfunction.cpp => sumofno_without_op_add.cpp} (100%) create mode 100644 C++/swap_without_temp.txt diff --git a/C++/sumofno_without_operator&addfunction.cpp b/C++/sumofno_without_op_add.cpp similarity index 100% rename from C++/sumofno_without_operator&addfunction.cpp rename to C++/sumofno_without_op_add.cpp diff --git a/C++/swap_without_temp.txt b/C++/swap_without_temp.txt new file mode 100644 index 0000000..62cdb3b --- /dev/null +++ b/C++/swap_without_temp.txt @@ -0,0 +1,15 @@ +// C++ Program to swap two numbers without using temporary variable + +#include +using namespace std; + +int main() +{ + int a = 11, b = 6; + + // Code to swap 'a' and 'b' + a = a + b; + b = a - b; + a = a - b; + cout << "After Swapping: a =" << a << ", b=" << b; +} \ No newline at end of file From 2e7395099e5e7a1dec8f71edff0f04bdaeae278e Mon Sep 17 00:00:00 2001 From: Samiksha Upadhyay Date: Thu, 7 Oct 2021 17:18:32 +0530 Subject: [PATCH 2/4] added swap_without_temp.cpp --- C++/{swap_without_temp.txt => swap_without_temp.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C++/{swap_without_temp.txt => swap_without_temp.cpp} (100%) diff --git a/C++/swap_without_temp.txt b/C++/swap_without_temp.cpp similarity index 100% rename from C++/swap_without_temp.txt rename to C++/swap_without_temp.cpp From a165ef3c28bb89b28f3bf5c6f31bbaaf19ad7617 Mon Sep 17 00:00:00 2001 From: Samiksha Upadhyay Date: Sun, 10 Oct 2021 19:20:05 +0530 Subject: [PATCH 3/4] added readme files --- C++/sumofnum_without_operator/readme.md | 5 +++++ .../sumofno_without_op_add.cpp | 0 C++/swap_without_temp/readme.md | 9 +++++++++ C++/{ => swap_without_temp}/swap_without_temp.cpp | 0 4 files changed, 14 insertions(+) create mode 100644 C++/sumofnum_without_operator/readme.md rename C++/{ => sumofnum_without_operator}/sumofno_without_op_add.cpp (100%) create mode 100644 C++/swap_without_temp/readme.md rename C++/{ => swap_without_temp}/swap_without_temp.cpp (100%) diff --git a/C++/sumofnum_without_operator/readme.md b/C++/sumofnum_without_operator/readme.md new file mode 100644 index 0000000..a27afce --- /dev/null +++ b/C++/sumofnum_without_operator/readme.md @@ -0,0 +1,5 @@ +## FIND SUM OF TWO NUMBERS WITHOUT USING ADDITION OPERATOR OR FUNCTION + +The following program has been written in ```C++``` : + +The program goes in a loop and stores the sum in one of the numbers, by using the increment operator. \ No newline at end of file diff --git a/C++/sumofno_without_op_add.cpp b/C++/sumofnum_without_operator/sumofno_without_op_add.cpp similarity index 100% rename from C++/sumofno_without_op_add.cpp rename to C++/sumofnum_without_operator/sumofno_without_op_add.cpp diff --git a/C++/swap_without_temp/readme.md b/C++/swap_without_temp/readme.md new file mode 100644 index 0000000..d52528c --- /dev/null +++ b/C++/swap_without_temp/readme.md @@ -0,0 +1,9 @@ +## SWAP TWO NUMBERS WITHOUT USING TEMPORARY VARIABLE + +The following program has been written in ```C++``` : + +The program first adds the two numbers and stores it in the first variable + +Then the numbers are subtracted and stored in the second variable + +Finally, the numbers (with the updated values) are subtracted and stored in the first variable hence successfully swapping it diff --git a/C++/swap_without_temp.cpp b/C++/swap_without_temp/swap_without_temp.cpp similarity index 100% rename from C++/swap_without_temp.cpp rename to C++/swap_without_temp/swap_without_temp.cpp From b4bdc24168430f7ac52fd42a89602400c0987828 Mon Sep 17 00:00:00 2001 From: Samiksha Upadhyay Date: Mon, 18 Oct 2021 19:05:57 +0530 Subject: [PATCH 4/4] added clock program in java --- Java/Clock display/Clock.java | 121 ++++++++++++++++++++++++++++++++++ Java/Clock display/readme.md | 1 + 2 files changed, 122 insertions(+) create mode 100644 Java/Clock display/Clock.java create mode 100644 Java/Clock display/readme.md diff --git a/Java/Clock display/Clock.java b/Java/Clock display/Clock.java new file mode 100644 index 0000000..3aa561b --- /dev/null +++ b/Java/Clock display/Clock.java @@ -0,0 +1,121 @@ +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; +import java.time.LocalTime; +import java.time.temporal.TemporalField; +import java.util.Date; +import java.util.concurrent.TimeUnit; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.Timer; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +public class Test +{ + + public static void main(String[] args) + { + new Test(); + } + + public Test() + { + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) + { + ex.printStackTrace(); + } + + JFrame frame = new JFrame("Testing"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new ClockFace()); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + }); + } + + public class ClockFace extends JPanel + { + + public ClockFace() + { + this.startClock(); + } + + @Override + public Dimension getPreferredSize() + { + return new Dimension(600, 600); + } + + @Override + protected void paintComponent(Graphics g) + { + Graphics2D g2d = (Graphics2D) g.create(); + + LocalTime now = LocalTime.now(); + int seconds = now.getSecond(); + int minutes = now.getMinute(); + int hours = now.getHour(); + + g2d.setColor(Color.BLACK); + g2d.fillRect(0, 0, 600, 600); + g2d.setColor(Color.WHITE); + g2d.translate(300, 300); + + //Drawing the hour markers + for (int i = 0; i < 12; i++) + { + + g2d.drawLine(0, -260, 0, -300); + g2d.rotate(Math.PI / 6); + + } + + g2d.rotate(seconds * Math.PI / 30); + g2d.drawLine(0, 0, 0, -290); + + g2d.rotate(2 * Math.PI - seconds * Math.PI / 30); + g2d.rotate(minutes * Math.PI / 30); + g2d.setStroke(new BasicStroke(3)); + g2d.drawLine(0, 0, 0, -250); + + g2d.rotate(2 * Math.PI - minutes * Math.PI / 30); + g2d.rotate(hours * Math.PI / 6); + g2d.setStroke(new BasicStroke(6)); + g2d.drawLine(0, 0, 0, -200); + + g2d.dispose(); + } + + public void startClock() + { + Timer timer = new Timer(500, new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + repaint(); + } + }); + timer.start(); + } + + } +} \ No newline at end of file diff --git a/Java/Clock display/readme.md b/Java/Clock display/readme.md new file mode 100644 index 0000000..795cb07 --- /dev/null +++ b/Java/Clock display/readme.md @@ -0,0 +1 @@ +This program creates a clock and displays it using java functions