Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Write a program to count Vowels and Consonants in string.
Input

The input will be a single line containing a string s.
Output

The first line of output should contain no of Vowels in the given string
The second line of output should  contain no of Consonants in the given string
Explanation

For example, if the given string is "Good Morning"
Vowels in the string "Good Morning" are "o, i" and their count is 4.
Remaining characters in the string are consonants their count is 7.
The First line of output is 4\nThe second line of output is 7.
Sample Input 1
Good Morning
Sample Output 1
4
7

Sample Input 2
welcome
Sample Output 2
3
4
Write a program to count even and odd numbers in given range [M, N]. Both M, N are inclusive in [M, N].
Input

The first line of the input will be an integer(M).
The Second line of the input will be an integer(N).
Output

The first line of output should be a number of odds count.
The second line of output should be a number of even counts.
Explanation

For example, if the given range is 2 to 11 
odds numbers in the range are 3, 5, 7, 9, 11 then count is 5.
even numbers in the range are 2, 4, 6, 8, 10 then count is 5.
Sample Input 1
2
11
Sample Output 1
5
5

Sample Input 2
-5
7
Sample Output 2
7
6

1.Write a program using one-dimensional array that accept 5 input values from the keyboard. Then it 

should also accept a number to search. This number is to be searched if it is among the five inputs. If 

it is found, display the message “Searched number is found!”, otherwise display “Search number is not 

included in the list”.


Sample Output:

Enter five values:

5 10 15 20 25

Enter a number to search: 15

Search number is found!


Matrix Rotations

You are given a square matrix A of dimensions NxN. You need to apply the below given 3 operations on the matrix A.


Rotation: It is represented as R S where S is an integer in {90, 180, 270, 360, 450, ...} which denotes the number of degrees to rotate. You need to rotate the matrix A by angle S in the clockwise direction. The angle of rotation(S) will always be in multiples of 90 degrees.


Update: It is represented as U X Y Z. In initial matrix A (as given in input), you need to update the element at row index X and column index Y with value Z.

After the update, all the previous rotation operations have to be applied to the updated initial matrix.


Querying: It is represented as Q K L. You need to print the value at row index K and column index L of the matrix A.


Input


The first line contains a single integer N.

Next N lines contain N space-separated integers Aij (i - index of the row, j - index of the column).

Next lines contain various operations on the array. Each operation on each line (Beginning either with R, U or Q).

-1 will represent the end of input.


Output


For each Query operation print the element present at row index K and colum index L of the matrix in its current state.


Explanation


For Input:

2

1 2

3 4

R 90

Q 0 0

Q 0 1

R 90

Q 0 0

U 0 0 6

Q 1 1

-1


Initial Matrix

1 2

3 4


For R 90, clockwise rotation by 90 degrees, the matrix will become

3 1

4 2


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 3.

For Q 0 1, print the element at row index 0 and column index 1 of A, which is 1.


Again for R 90, clockwise rotation by 90 degrees, the matrix will become

4 3

2 1


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 4.


For U 0 0 6, update the value at row index 0 and column index 1 in the initial matrix to 6. So the updated matrix will be,

6 2

3 4

After updating, we need to rotate the matrix by sum of all rotation angles applied till now(i.e. R 90 and R 90 => 90 + 90 => 180 degrees in clockwise direction).

After rotation the matrix will now become

4 3

2 6


Next for Q 1 1, print the element at row index 1 and column index 1 of A, which is 6.

output

3

1

4

6

Sample Input 1

2

1 2

3 4

R 90

Q 0 0

Q 0 1

R 90

Q 0 0

U 0 0 6

Q 1 1

-1

Sample Output 1

3

1

4

6

Sample Input 2

2

5 6

7 8

R 90

Q 0 1

R 270

Q 1 1

R 180

U 0 0 4

Q 0 0

-1

Sample Output 2

5

8

8




Temperature Conversion

You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.

Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.

Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.

Formula to convert from Kelvin K to Celsius C is C = K - 273.

Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.

The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.

The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.Input


The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.Output


The first line of output should contain the Celsius value and the unit of the Celsius without any space.

The second line of output should contain the Fahrenheit value and the unit of the Fahrenheit without any space.

The third line of output should contain the Kelvin value and the unit of the Kelvin without any space.Explanation


For example, if the given temperature Value is 25C then Celsius value is 25.0C, Fahrenheit value is 77.0F, and Kelvin value is 298.0K.

Sample Input 1

25C

Sample Output 1

25.0C

77.0F

298.0K

Sample Input 2

37.5F

Sample Output 2

3.06C

37.5F

276.06K


You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.
Input

The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.
Output

The first line of output should contain the Celsius value and the unit of the Celsius without any space.
The second line of output should contain the Fahrenheit value and the unit of the Fahrenheit without any space.
The third line of output should contain the Kelvin value and the unit of the Kelvin without any space.
Explanation

For example, if the given temperature Value is 25C then Celsius value is 25.0C, Fahrenheit value is 77.0F, and Kelvin value is 298.0K.
Sample Input 1
25C
Sample Output 1
25.0C
77.0F
298.0K

Sample Input 2
37.5F
Sample Output 2
3.06C
37.5F
276.06K

Tic-Tac-Toe game


Abhinav and Anjali are playing the Tic-Tac-Toe game. Tic-Tac-Toe is a game played on a grid that's three squares by three squares. Abhinav is O, and Anjali is X. Players take turns putting their marks in empty squares. The first player to get 3 of her marks in a diagonal or horizontal, or vertical row is the winner. When all nine squares are complete, the game is over. If no player has three marks in a row, the game ends in a tie. Write a program to decide the winner in the Tic-Tac-Toe game.


Input


The input will be three lines contain O's and X's separated by space.


Output


The output should be a single line containing either "Abhinav Wins" or "Anjali Wins" or "Tie".


Explanation


For example, if the input is

O X O
O X X
O O X 

as three of O's are in vertical row print "Abhinav Wins".


Sample Input 1


O X O

O X X

O O X


Sample Output 1

Abhinav Wins


Sample Input 2


O O X

X X O

X O O


Sample Output 2

Anjali Wins




Coding

The minimal requirements of your program are:

•                 Present the user with a menu, wherein s/he may decide:

◦  Which dishes to make (with up to four dishes, this means up to 4 threads)

◦  The number of each dish to prepare (ideally a separate number for each dish)

◦  How often should progress be reported? (Explained further below)

•                 Start a thread for each dish

◦  Each type should be implemented into its own thread, since it has its own lock requirements

◦  Each dish tries to report upon completing one (subject to above/below)

◦  Each dish type always reports when completed its iterations

▪  Obviously there's no reporting if none are being made at all

•                 The program then reports on the total number of dishes produced

•                 If this isn't obvious, increasing the tally and output are also a 'resource'



Additional notes:

Write your threads immensely clearly, and comment it.

•                 Comment usefully. Don't add nonsense like identifying that a loop “loops”, or that .lock() “locks”

•                 Also, proper indentation, please?

Obviously, you'll have several .java files for this (if using Java).

Pseudo Code:

import threading


todo=2000000

confirmed=0

lock=threading.Semaphore() #We had some interesting options here


def worker(id):

global todo, confirmed

print("\t"+str(id)+" thinking...")

while True:

#We could do extra work here


lock.acquire() #Either acquire

the lock, or block until it's ready

if todo==0:

break

todo-=1

confirmed+=1

lock.release()  

#We could also do work here

print("\t"+str(id)+" completed!")


t1=threading.Thread(target=worker, args=(1,))

t2=threading.Thread(target=worker, args=(2,))

t1.start()

t2.start()

t1.join()

t2.join()

print("Done!\n"+str(confirmed))

Output Should be like

would you like any frozen pizzas? (y/n)y

How many would you like 1000000

would you like any pastas? (y/n)y

How many would you like 1000000

would you like any pizzas? (y/n)y

How many would you like 1000000

would you like any chicken? (y/n)y

How many would you like 1000000

At what rate would you like to recieve reports? 100000

Frozen pizzas starting...

Pastas starting...

Pizzas starting...

Chicken starting...

100000 Frozen Pizzas completed!

200000 Frozen Pizzas completed!

300000 Frozen Pizzas

completed!

400000 Frozen Pizzas completed!

500000 Frozen Pizzas completed!

600000 Frozen Pizzas completed!

700000 Frozen Pizzas completed!

100000 Chickens completed!

800000 Frozen Pizzas completed!

900000 Frozen Pizzas completed!

1000000 Frozen Pizzas completed!

Frozen Pizzas Complete

100000 Pastas completed!

100000 Pizzas completed!

200000 Chickens completed!

200000 Pizzas completed!

300000 Chickens completed!

300000 Pizzas completed!

200000 Pastas completed!

400000 Chickens completed!

400000 Pizzas completed!

500000 Chickens completed!

300000 Pastas completed!

500000 Pizzas completed!

600000 Chickens completed!

600000 Pizzas completed!

700000 Chickens completed!

400000 Pastas completed!

700000 Pizzas completed!

800000 Chickens completed!

800000 Pizzas completed!

500000 Pastas completed!

900000 Chickens completed!

900000 Pizzas completed!

1000000 Chickens completed!

Chicken Complete

600000 Pastas completed!

1000000 Pizzas completed!

Pizzas Complete

700000 Pastas completed!

800000 Pastas completed!

900000 Pastas completed!

1000000 Pastas completed!

Pastas Complete

Done!

4000000 items made



Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, I-405 services I-5, and I-290 services I-90.

Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.

Ex: If the input is:

90

the output is:

I-90 is primary, going east/west.

Ex: If the input is:

290

the output is:

I-290 is auxiliary, serving I-90, going east/west.

Ex: If the input is:

0

the output is:

0 is not a valid interstate highway number.

Write a program that finds the area of circle, triangle, rectangle and square using a function named area. In this program, use a single class named shape which contains various implementations of ‘area’. Your program should dynamically decide which shapes area has to be found depending on the type of input. The radius is float value, base and height of triangle are double values, sides of rectangle and square are integer values.


LATEST TUTORIALS
APPROVED BY CLIENTS