Assignment No.3. /*-- Program for addition of two numbers using C++ --*/



Similar documents
Homework/Program #5 Solutions

Chapter 2 Introduction to Java programming

Introduction to Java

JAVA ARRAY EXAMPLE PDF

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

The following program is aiming to extract from a simple text file an analysis of the content such as:

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Sample CSE8A midterm Multiple Choice (circle one)

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Topic 11 Scanner object, conditional execution

Basics of Java Programming Input and the Scanner class

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Building Java Programs

Install Java Development Kit (JDK) 1.8

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CS 121 Intro to Programming:Java - Lecture 11 Announcements

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Introduction to Programming

AP Computer Science Java Mr. Clausen Program 9A, 9B

Programmierpraktikum

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Part I. Multiple Choice Questions (2 points each):

Chapter 2: Elements of Java

Building Java Programs

(Eng. Hayam Reda Seireg) Sheet Java

J a v a Quiz (Unit 3, Test 0 Practice)

Introduction to Java. CS 3: Computer Programming in Java

Lösningsförslag till tentamen

AP Computer Science Static Methods, Strings, User Input

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

OBJECT ORIENTED PROGRAMMING LANGUAGE

Building Java Programs

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Object-Oriented Programming in Java

Week 1: Review of Java Programming Basics

Tutorial Reference Manual. Java WireFusion 4.1

Building Java Programs

More on Objects and Classes

Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1

Example of a Java program

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;

Chapter 2 Elementary Programming

Introduction to Object-Oriented Programming

Web Development and Core Java Lab Manual V th Semester

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html

Course Intro Instructor Intro Java Intro, Continued

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Contents. 9-1 Copyright (c) N. Afshartous

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

WHAT ARE PACKAGES? A package is a collection of related classes. This is similar to the notion that a class is a collection of related methods.

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Analysis Of Source Lines Of Code(SLOC) Metric

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Comp 248 Introduction to Programming

Chapter 3. Input and output. 3.1 The System class

Object Oriented Software Design

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

6.1. Example: A Tip Calculator 6-1

13 File Output and Input

Java Crash Course Part I

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

Using Files as Input/Output in Java 5.0 Applications

COMPUTER SCIENCE 1999 (Delhi Board)

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Event-Driven Programming

Object Oriented Software Design

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main.

Programming and Data Structures with Java and JUnit. Rick Mercer

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Arrays in Java. Working with Arrays

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

An Overview of Java. overview-1

Algorithms and Data Structures Written Exam Proposed SOLUTION

java Features Version April 19, 2013 by Thorsten Kracht

Graphical User Interfaces

Statements and Control Flow

Chapter 1 Java Program Design and Development

CS 335 Lecture 06 Java Programming GUI and Swing

Using Two-Dimensional Arrays

Programming with Java GUI components

CSE 8B Midterm Fall 2015

Arrays. Introduction. Chapter 7

1.00/ Session 2 Fall Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

Transcription:

Assignment No.3 /*-- Program for addition of two numbers using C++ --*/ #include<iostream.h> class add private: int a,b,c; public: void getdata() cout<<"\nenter value of a:"; cin>>a; cout<<"\nenter value of b:"; cin>>b; void adddata() c=a+b; void displayall() cout<<"values of all variables:"; cout<<"\n a="<<a; cout<<"\n b="<<b; cout<<"\n c="<<c; ; int main() add obj; obj.getdata(); obj.adddata(); obj.displayall(); return (0);

//-----Output of CPP Program to add two integers ----- Enter value of a:30 Enter value of b:40 Values of all variables: a=30 b=40 c=70 /*-- Program for addition of two numbers using JAVA --*/ import java.util.*; public class AddNumber public static void main(string[] args) int a,b,result; System.out.println("Enter two numbers"); Scanner add =new Scanner(System.in); a=add.nextint(); b=add.nextint(); result=a+b; System.out.println("result ="+result); add.close(); //-------Output of JAVA Program to add two integers --- Enter two numbers 10 20 result =30

Assignment No.4 /*-- Program for finding palindrome using java class --*/ import java.util.scanner; public class palindrome1 public static void main(string[] args) // input user string System.out.println("Enter string:"); Scanner value=new Scanner(System.in); String str=value.next(); //create array of char and reverse array char [] arr=str.tochararray(); int size=str.length(); char [] rev=new char[size]; for(int i=0;i<size;i++) System.out.println(arr [i]); rev[size-1-i]=arr[i]; //compare arrays to check palindrome System.out.println(new String(rev)); boolean palindrome=true; for(int i=0;i<size;i++) if(arr[i]!=rev[i]) palindrome=false; break;

//display result if(palindrome==true) System.out.println("palindrome"); else System.out.println("not palindrome"); value.close(); //--------- Output --------------------- Key found at location: 4 Enter string: RSCOE RSCOE EOCSR not palindrome Enter string: DAD DAD DAD palindrome

Assignment No.5 /*---- Program for Binary Search using java class ---*/ //----------------- BinarySearch.java --------------- public class BinarySearch public void search (int a[],int low, int high,int key) int mid; if (low>high) System.out.println("key not found "); return; mid=(low+high)/2; if (key==a[mid]) System.out.println("key found at location;"+(mid+1)); else if(key<a[mid]) search (a,mid-1,high,key); else if(key>a[mid]) search(a,mid+1,high,key);

//------------------- Mainclass.java ------------------- public class Mainclass public static void main(string[] args) int a[]=10,20,30,40,50,60,70,80,90,100; int key=20; int low=0; int high=9; BinarySearch obj=new BinarySearch(); obj.search( a,low,high,key); //-------- Output ------------------- Key found at location: 2

Assignment No.6 /*Program for showing the current TIME and DATE using java class */ import java.util.*; import java.text.dateformat; import java.text.simpledateformat; public class DateTime public static void main(string[] args) DateFormat d2=new SimpleDateFormat("HH:mm:ss:SS:K "); DateFormat d1=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date d=new Date(); System.out.println("The current Date and Time is " +d1.format(d)); System.out.println("To Display Hours:mins:sec:millisec:Hour In AM/PM:"+d2.format(d)); //----------- Output ------------ The current Date and Time is :2013/03/19 11:00:19 To Display Hours:mins:sec:millisec:Hour In AM/PM :11:00:19:265:11

Assignment No.7 /*----- Program for Simple Calculator using C++ -----*/ #include<iostream.h> #include<conio.h> class Calci private: int a,b,result; float c,d,res; public: void sum() cout<<"enter two numbers:\n"; cin>>a>>b; result=a+b; cout<<"addition="<<result; void sub() cout<<"enter two numbers:\n"; cin>>a>>b; result=a-b; cout<<"subtraction="<<result; void mult() cout<<"enter two numbers:\n"; cin>>a>>b; result=a*b; cout<<"multiplication="<<result; void div() cout<<"enter two numbers:\n"; cin>>c>>d; res=c/d; cout<<"division="<<res;

void mod() cout<<"enter two numbers:\n"; cin>>a>>b; result=a%b; cout<<"remainder after Division="<<result; ; void main () clrscr(); int choice; cout<<"simple Calculator"; cout<<"\n1.addition\n2.subtraction\n3.multiplication\n4.d ivision\n5.modulus ; cout<< \nplease Enter Your Choice:"; cin>>choice; Calci c; switch(choice) case 1: c.sum(); break; case 2: c. sub(); break; case 3:c.mult(); break; case 4:c.div(); break; case 5:c.mod(); break; default: cout<<"invalid choice"; getch();

/*---------------------------OUTPUT--------------------- Simple Calculator 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulus Please Enter Your Choice: 4 Enter two numbers: 15 10 Division= 1.5 Simple Calculator 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulus Please Enter Your Choice: 1 Enter two numbers: 1 100 Addition= 101

Assignment No.8 /*--- Program for Simple Calculator using Applet -----*/ import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="cal" width=300 height=300> </applet> */ public class Cal extends Applet implements ActionListener String msg=" "; int v1,v2,result; TextField t1; Button b[]=new Button[10]; Button add,sub,mul,div,clear,mod,eq; char OP; public void init() Color k=new Color(120,89,90); setbackground(k); t1=new TextField(10); GridLayout gl=new GridLayout(4,5); setlayout(gl); for(int i=0;i<10;i++) b[i]=new Button(""+i); add=new Button("add"); sub=new Button("sub"); mul=new Button("mul"); div=new Button("div");

mod=new Button("mod"); clear=new Button("clear"); EQ=new Button("EQ"); t1.addactionlistener(this); add(t1); for(int i=0;i<10;i++) add(b[i]); add(add); add(sub); add(mul); add(div); add(mod); add(clear); add(eq); for(int i=0;i<10;i++) b[i].addactionlistener(this); add.addactionlistener(this); sub.addactionlistener(this); mul.addactionlistener(this); div.addactionlistener(this); mod.addactionlistener(this); clear.addactionlistener(this); EQ.addActionListener(this); public void actionperformed(actionevent ae) String str=ae.getactioncommand(); char ch=str.charat(0); if( Character.isDigit(ch)) t1.settext(t1.gettext()+str);

else if(str.equals("add")) v1=integer.parseint(t1.gettext()); OP='+'; t1.settext(""); else if(str.equals("sub")) v1=integer.parseint(t1.gettext()); OP='-'; t1.settext(""); else if(str.equals("mul")) v1=integer.parseint(t1.gettext()); OP='*'; t1.settext(""); else if(str.equals("div")) v1=integer.parseint(t1.gettext()); OP='/'; t1.settext(""); else if(str.equals("mod")) v1=integer.parseint(t1.gettext()); OP='%'; t1.settext(""); if(str.equals("eq")) v2=integer.parseint(t1.gettext()); if(op=='+') result=v1+v2; else if(op=='-') result=v1-v2;

else if(op=='*') result=v1*v2; else if(op=='/') result=v1/v2; else if(op=='%') result=v1%v2; t1.settext(""+result); if(str.equals("clear")) t1.settext(""); //------------------- Output ---------------------