What is a program that calculates the sum of any 5 digit integer number entered by user?
#include<iostream>
unsigned sum_of_digits(unsigned num)
{
unsigned sum = 0;
do
{
sum += num%10;
} while (num/=10);
return sum;
}
int main()
{
unsigned number = 12345;
unsigned sum = sum_of_digits (number);
std::cout << "Sum of digits in " << number << " is " << sum << std::endl;
}
Implement an assembly code that counts the number of vowels in a given string?
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'Enter a string : $'
PROMPT_2 DB 0DH,0AH,'No. of Vowels = $'
PROMPT_3 DB 0DH,0AH,'No. of Consonants = $'
STRING DB 50 DUP (?)
C_VOWELS DB 'AEIOU'
S_VOWELS DB 'aeiou'
C_CONSONANTS DB 'BCDFGHJKLMNPQRSTVWXYZ'
S_CONSONANTS DB 'bcdfghjklmnpqrstvwxyz'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS and ES
MOV DS, AX
MOV ES, AX
LEA DX, PROMPT_1 ; load and display the string PROMPT_1
MOV AH, 9
INT 21H
LEA DI, STRING ; set DI=offset address of variable STRING
CALL READ_STR ; call the procedure READ_STR
XOR DX, DX ; clear DX
LEA SI, STRING ; set SI=offset address of variable STRING
OR BX, BX ; check BX for 0
JE @EXIT ; jump to label @EXIT if BX=0
@COUNT: ; jump label
LODSB ; set AL=DS:SI
LEA DI, C_VOWELS ; set DI=offset address of variable C_VOWELS
MOV CX, 5 ; set CX=5
REPNE SCASB ; check AL is capital vowel or not
JE @INCREMENT_VOWELS ; jump to label @INCREMENT_VOWELS if AL is
; capital vowel
LEA DI, S_VOWELS ; set DI=offset address of variable S_VOWELS
MOV CX, 5 ; set CX=5
REPNE SCASB ; check AL is small vowel or not
JE @INCREMENT_VOWELS ; jump to label @INCREMENT_VOWELS if AL is
; small vowel
LEA DI, C_CONSONANTS ; set DI=offset address of variable
; C_CONSONANTS
MOV CX, 21 ; set CX=21
REPNE SCASB ; check AL is capital consonant or not
JE @INCREMENT_CONSONANTS ; jump to label @INCREMENT_CONSONANTS if AL
; is capital consonant
LEA DI, S_CONSONANTS ; set DI=offset address of variable
; S_CONSONANTS
MOV CX, 21 ; set CX=21
REPNE SCASB ; check AL is small consonant or not
JE @INCREMENT_CONSONANTS ; jump to label @INCREMENT_CONSONANTS if AL
; is small consonants
JMP @NEXT ; otherwise, jump to label @NEXT
@INCREMENT_VOWELS: ; jump label
INC DL ; increment DL
JMP @NEXT ; jump to label @NEXT
@INCREMENT_CONSONANTS: ; jump label
INC DH ; increment DH
@NEXT: ; jump label
DEC BX ; decrement BX
JNE @COUNT ; jump to label @COUNT while BX!=0
@EXIT: ; jump label
MOV CX, DX ; set CX=DX
LEA DX, PROMPT_2 ; load and display the string PROMPT_2
MOV AH, 9
INT 21H
XOR AX, AX ; clear AX
MOV AL, CL ; set AL=CL
CALL OUTDEC ; call the procedure OUTDEC
LEA DX, PROMPT_3 ; load and display the string PROMPT_3
MOV AH, 9
INT 21H
XOR AX, AX ; clear AX
MOV AL, CH ; set AL=CH
CALL OUTDEC ; call the procedure OUTDEC
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
READ_STR PROC
; this procedure will read a string from user and store it
; input : DI=offset address of the string variabel
; output : BX=number of characters read
; : DI=offset address of the string variabel
PUSH AX ; push AX onto the STACK
PUSH DI ; push DI onto the STACK
CLD ; clear direction flag
XOR BX, BX ; clear BX
@INPUT_LOOP: ; loop label
MOV AH, 1 ; set input function
INT 21H ; read a character
CMP AL, 0DH ; compare AL with CR
JE @END_INPUT ; jump to label @END_INPUT if AL=CR
CMP AL, 08H ; compare AL with 08H
JNE @NOT_BACKSPACE ; jump to label @NOT_BACKSPACE if AL!=08H
CMP BX, 0 ; compare BX with 0
JE @INPUT_ERROR ; jump to label @INPUT_ERROR if BX=0
MOV AH, 2 ; set output function
MOV DL, 20H ; set DL=20H
INT 21H ; print a character
MOV DL, 08H ; set DL=08H
INT 21H ; print a character
DEC BX ; set BX=BX-1
DEC DI ; set DI=DI-1
JMP @INPUT_LOOP ; jump to label @INPUT_LOOP
@INPUT_ERROR: ; jump label
MOV AH, 2 ; set output function
MOV DL, 07H ; set DL=07H
INT 21H ; print a character
MOV DL, 20H ; set DL=20H
INT 21H ; print a character
JMP @INPUT_LOOP ; jump to label @INPUT_LOOP
@NOT_BACKSPACE: ; jump label
STOSB ; set ES:[DI]=AL
INC BX ; set BX=BX+1
JMP @INPUT_LOOP ; jump to label @INPUT_LOOP
@END_INPUT: ; jump label
POP DI ; pop a value from STACK into DI
POP AX ; pop a value from STACK into AX
RET
READ_STR ENDP
OUTDEC PROC
; this procedure will display a decimal number
; input : AX
; output : none
PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
CMP AX, 0 ; compare AX with 0
JGE @START ; jump to label @START if AX>=0
PUSH AX ; push AX onto the STACK
MOV AH, 2 ; set output function
MOV DL, "-" ; set DL='-'
INT 21H ; print the character
POP AX ; pop a value from STACK into AX
NEG AX ; take 2's complement of AX
@START: ; jump label
XOR CX, CX ; clear CX
MOV BX, 10 ; set BX=10
@OUTPUT: ; loop label
XOR DX, DX ; clear DX
DIV BX ; divide AX by BX
PUSH DX ; push DX onto the STACK
INC CX ; increment CX
OR AX, AX ; take OR of Ax with AX
JNE @OUTPUT ; jump to label @OUTPUT if ZF=0
MOV AH, 2 ; set output function
@DISPLAY: ; loop label
POP DX ; pop a value from STACK to DX
OR DL, 30H ; convert decimal to ascii code
INT 21H ; print a character
LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0
POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP BX ; pop a value from STACK into BX
RET ; return control to the calling procedure
OUTDEC ENDP
END MAIN
What are the keywords not used in java?
You can find a list of Java keywords in the Wikipedia article "List of Java keywords". These keywords may not be used for variables or other user-defined names.
Java is not an abbreviation. Java does not expand itself into anything. It is a programming language that is portable, platform independent and object oriented. It is used widely in computer software and in enterprise class applications all over the world.
What is the use of base keyword?
Using base in a derived class invokes the base class's corresponding method.
For example, something like:
class Shape{
public void print(){printf("Generic shape");
...
}
class Triangle:Shape{
public void print(){printf("Triangle");
...
}
int main()
{
Triangle x;
x.print(); // Should print "Triangle"
x.base.print(); // Should print "Generic shape"
return 0;
}
server side networking application ServerSocket class is used, in this class method named as serversocket_object.accept() is used by server to listen to clients at specific port addresses, for local computer it is either "localhost" or "127.0.0.1" and might be u'r subnet address in case of some LAN.
What is the argument of main()method?
In Java, the main() method is typically written something like this:public static void main(String [ ] args)
The argument is what is in parentheses, in this case: "String [] args". I believe this can also be written as "String args[]". It refers to parameters received by the Java program from the command line. That is, the user can write, for example:
java MyClass info1 info2
In this example, "info1" and "info2" will be received by the main method, in the args[] array.
Why is overloading a watercraft considered reckless and negligent behaviour?
Overloading a watercraft could cause a capsize and the vessel to sink.
Read five integers and prints the largest and smallest integer using java?
{
// set up our input buffer
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String currentLine;
// store our ints in a list
int smallest = 0;
int largest = 0;
// counter
int numIntsRead = 0;
// force smallest and largest to start as the first proper int entered
while (numIntsRead < 1) {
currentLine = in.readLine();
try {
// convert from string to int
int currentNumber = Integer.parseInt(currentLine);
smallest = currentNumber;
largest = currentNumber;
++numIntsRead;
} catch (final NumberFormatException ex) {
// we go here if the user didn't type in an integer
}
}
// loop until we read all 5 ints
while (numIntsRead < 5) {
currentLine = in.readLine();
try {
// convert from string to int
int currentNumber = Integer.parseInt(currentLine);
if (currentNumber < smallest) {
smallest = currentNumber;
}
if (currentNumber > largest) {
largest = currentNumber;
}
++numIntsRead;
} catch (final NumberFormatException ex) {
// we go here if the user didn't type in an integer
}
}
// display our findings
System.out.println("Smallest:\t" + smallest);
System.out.println("Largest:\t" + largest);
}
What does Java 2 Runtime Environment SE v1.4.1 01java do?
This softwear peovides an environment for JAVA. When you are using some function on web to establish something, you need it.
For example, when I was using "ISI WEB OF KNOWLEDGE", I wank to know the relationship amond the article and other articles who cite it. I press the button "Creat Citation Alert" . Then I need a JAVA program to help me draw out the picture. If I don't have that "Runtime Environment" the JAVA program won't run. I'm not going to get the picture.
Type casting means to explicitly convert one type to another.
For example, the following lines:
double x = 5.0;
int y = x;
will produce an error message, because of a possible loss of precision (any decimals will get lost when converting to int). The following will work however:
double x = 5.0;
int y = (int) x;
The programmer is forcing the Java compiler to accept the conversion; saying, in effect: "Please do this anyway, I know what I am doing".
How can you make a beep sound using java?
Its very easy to make a beep sound using Toolkit in java...
Here is the program...
import java.awt.*;
public class BeepExample
{
public static void main(String[] args)
{
Toolkit.getDefaultToolkit().beep();
}
}
Why was java developed and what is the purpose of this programming language?
It is object oriented language in which All program is to be written inside a specific class. it is more comfortable and less coding required to build program.
How do you write a program to check the string of a given grammar?
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char string[50];
int flag,count=o;
clrscr();
printf("The grammar is: S->aS, S->Sb, S->ab\n");
printf("Enter the string to be checked:\n");
gets(string);
if(string[0]=='a')
{
flag=0;
for(count=1;string[count-1]!='\0';count++)
{
if(string[count=='b'])
{
flag=1;
continue;
}
else if((flag==1)&&(string[count]=='a'))
{
printf("The string does not belong to the specified grammar");
break;
}
else if(string[count=='a'])
continue;
else if(flag==1)&&(string[count]='\0'))
{
printf("The string accepted");
break;
}
else
{
printf("String not accepted");
}
getch():
Write a program in java to print r er ter uter puter mputer omputer computer?
/* OUTPUT:
* R
* ER
* TER
* UTER
* PUTER
* MPUTER
* OMPUTER
* COMPUTER
*/
import java.io.*;
import java.lang.*;
class SuperbSeries
{
protected static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String s="COMPUTER";
for(short i=1;i<=s.length();i++)
{
for(short j=(short)(s.length()-i);j<s.length();j++)
{
System.out.print(s.charAt(j));
}
System.out.println();
}
}}
Yes.
What is the need for another oops language java instead of c?
actually the c language is the procedure based language n emphasis on the procedure. on tyhe other hand the java is object oriented lannguage,emphasis on the data and it's importance.
Refinement
Java is platform independent language and it made it more popular in creating embedded system. As its bytecode can be transferred to any platform so there was no need to implement compiler in the embedded system but JVM(a runtime systme) was required to be installed in embedded software.
Moreover the runtime was also reduced as it was not required to be compiled again.
http:\\in-central.blogspot.com
What is defferred exceptional handling?
Deferred exception handling refers to a programming design pattern where individual class level methods do not handle exceptions using try catch blocks. They just cascade the exceptions to the calling methods using the "throw" keyword and all exceptions are handled centrally in one place. This is called deferred exception handling where the exceptions are deferred in the place where they occur and propagated to a parent class which handles it.
Real time example for user defined exceptions?
class My_Exception {};
void f (int x) {
if (x==0) throw My_Exception;
// ...
}
int main () {
try {
f (42); // ok
f (0); // will throw
} catch (const My_Exception& err) {
std::cerr << "Invalid argument in f()\n";
}
}
What is used to control flow of the Java program?
Control flow mechanisms in Java include: if-else statements Example: if (a == b) System.out.println("They are equal."); else System.out.println("They are different."); endif (Here, and in the following examples, the single command can be replaced by a block in curly braces.) switch statementsExample: switch (number) { case 1: System.out.println("One"); break; case 2: System.out.println("Two"); break; case 3: System.out.println("Three"); break; default: System.out.println("Some other number"); break; loops (for, do, while): For loops, example: for(int i = 1; i
Program to find largest and smallest element in a matrix and print its position using c language?
#include
using std::cin;
using std::cout;
using std::endl;
void setData(double data[], const int& dataSize);
void min(const double data[], const int& dataSize);
void max(const double data[], const int& dataSize);
int main()
{
const int numberOfElements = 6;
double myArray[numberOfElements] = {0.0};
cout << endl << "Enter " << numberOfElements << " elements of your array" << endl;
setData(myArray, numberOfElements);
min(myArray, numberOfElements);
max(myArray, numberOfElements);
cout << endl;
system("PAUSE");
return 0;
}
void setData(double data[], const int& dataSize)
{
for (int i(0); i < dataSize; i++)
{
cout << (i + 1) << " element: ";
cin >> data[i];
}
}
void min(const double data[], const int& dataSize)
{
int minValPos(0);
double minVal = data[0];
for (int i(0); i < dataSize; i++)
{
if (minVal > data[i])
{
minVal = data[i];
minValPos = i;
}
}
cout << endl << "Minimum value is: " << minVal
<< " its position is: " << minValPos << endl;
return;
}
void max(const double data[], const int& dataSize)
{
int maxValPos(0);
double maxVal = data[0];
for (int i(0); i < dataSize; i++)
{
if (maxVal < data[i])
{
maxVal = data[i];
maxValPos = i;
}
}
cout << endl << "Maximum value is: " << maxVal
<< " its position is: " << maxValPos << endl;
return;
}