Tuesday, 31 December 2019

How do I store binary data in MySQL?

Q: How do I store binary data in MySQL?

Solution:

The basic answer is in a BLOB data type / attribute domain. BLOB is short for Binary Large Object and that column data type is specific for handling binary data.

you should be aware that there are other binary data formats:
TINYBLOB/BLOB/MEDIUMBLOB/LONGBLOB
VARBINARY
BINARY
Each has their use cases. If it is a known (short) length (e.g. packed data) often times BINARY or VARBINARY will work. They have the added benefit of being able ton index on them.


For a table like this:
CREATE TABLE binary_data (
    id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    description CHAR(50),
    bin_data LONGBLOB,
    filename CHAR(50),
    filesize CHAR(50),
    filetype CHAR(50)
);

Monday, 23 December 2019

Quick book payment integration

I am attempting to incorporate quick book to send and receive payments. But I can't locate api for payment (To send and receive payments to others). Furthermore, I am unable to locate api  to get bank transactions linked with quick book. Client has quick book software but want to fetch transaction in other software.

Solution:

Quick Book does not support any APIs to send and receive payments to others. This is not something that Quick Book / Intuit Payments supports.

Saturday, 7 December 2019

The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below

Q: The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration) BOS = [2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93] SEA = [6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85] Where the elements in the vectors are in the order of the months (January, February, etc.) Write your program to answer the following: (a) Calculate the total precipitation for the year and monthly average precipitation in each city. Do NOT use MATLAB's built-in functions sum and mean. (b) How many months was the precipitation above the average in each city? (c) How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle? 

Solution:

 
clear all;
close all;
bos=[2.67,1,1.21,3.09,3.43,4.71,3.88,3.08,4.10,2.62,1.01,5.93];
sea=[6.83,3.63,7.20,2.68,2.05,2.96,1.04,0,0.03,6.71,8.28,6.85];
tot_bos=0;
tot_sea=0;
for x=1:1:12
tot_bos=tot_bos+bos(x);
tot_sea=tot_sea+sea(x);
end
avg_bos=tot_bos/12;
avg_sea=tot_sea/12;
above_avg_bos=0;
above_avg_sea=0;
for y=1:1:12
if(bos(y)>avg_bos)
above_avg_bos=1+above_avg_bos
end;
if(sea(y)>avg_sea)
above_avg_sea=1+above_avg_sea
end;
end
i=1;
for z=1:1:12
if(bos(z)<sea(z));
a(i)=z;
i=i+1;
end
end
fprintf('Total participation for the year in BOS ans SEA are %0.2d %0.2d\n',tot_bos,tot_sea);
fprintf('Monthly avg participation for the year in BOS ans SEA are %0.2d %d\n',avg_bos,avg_sea);
fprintf('Totoal month of above avg participation in the year for BOS and SEA %i %i\n',above_avg_bos,above_avg_sea);
fprintf('Total month where BOS is less than SEA %i and months are %i',i-1,a);

The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below

Q: The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration). BOS = [2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93] SEA = [6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85] where the elements in the vectors are in the order of the months (January, February, etc.) Write a program to answer the following: Calculate the total precipitation for the year and monthly average precipitation in each city. How many months was the precipitation above the average in each city? (c) How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle?

Solution:

 
bos = [2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93];
sea = [6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85];
fprintf('Total precipitation in Boston=%f \n',sum(bos));
fprintf('Total precipitation in Seattle=%f \n',sum(sea));
fprintf('Average monthly precipitation in Boston=%f \n',sum(bos)/12);
fprintf('Average monthly precipitation in Seattle=%f \n',sum(sea)/12);
numMonthBos=0;
for v=bos
if v > sum(bos)/12
numMonthBos+=1;
end
end
numMonthSea=0;
for v=bos
if v > sum(sea)/12
numMonthSea+=1;
end
end
fprintf('Number of months when precipitation is above average in Boston=%d \n',numMonthBos);
fprintf('Number of months when precipitation is above average in Seattle=%d \n',numMonthSea);
total1=0;
for i=1:12
if bos(i) < sea(i)
total1+=1;
end
end
fprintf('Number of months when precipitation is lower in boston than in Seattle=%d \n',total1);

sh-4.3$ octave -qf --no-window-system demo.m octave: X11 DISPLAY environment variable not set octave: disabling warning: func

Write a program that will collect numbers from the user until the user enters a non-numeric value.

Q:
MATLAB Help:
Write a program that will collect numbers from the user until the user enters a non-numeric value. It then returns the sum and the average of all the numbers entered. Example below:
-----
Enter a number: 2.5
Enter a Number: 2
Enter a Number: 59
Enter a Number: 2
Enter a Number: 9
Enter a Number: 1.1
Enter a Number: k
The sum of the 6 numbers entered is 75.6. The average is 12.6.

Solution:

result = 0;
count = 0;
while(1)
val = input("Enter a number: ",'s')
val = str2double(val)
if(val == NaN)
break;
else
result = result + val;
end
count = count + 1;
end
fprintf("The sum of the %d numbers entered is %f. The average is %f.\n",count,result, (result/count));

Write a program that will collect one positive integer from the user. Validation is required.

Q:
MATLAB Help:
Write a program that will collect one positive integer from the user. Validation is required. Specifications:
1. The program should collect the input as a string and convert it to a numeric number
2. The program will check if the user enters nothing, a non-numeric value, or not a positive integer. It will keep prompting until the user enters a positive integer.
3. Design a prompt/feedback
Functions you may need: isempty(), isnan(), length(), str2double(), str2num()

Solution:


k=1;
while k==1
    k=0;
    num=input('Enter number: ','s');
    if isempty(num)
        k=1;
        fprintf('you did not enter anything\n')
    elseif isnan(str2double(num))
        k=1;
        fprintf('You entered a non numeric value\n')
    elseif str2double(num)<0
        k=1;
        fprintf('Please enter a positive value\n')
    else
        num=str2double(num);
    end
end
fprintf('You entered :%i\n',num)

Mini-program: Write a console program that prompts the user for an integer.

Q: Mini-program: Write a console program that prompts the user for an integer. As long as the user keeps entering positive integers, continue prompting for the next integer. Once the user enters an integer of 0 or less, report the largest integer that was entered and end the program.

Solution:

save it as test.c and in linux or ubuntu
Please run it using command : gcc -o test test.c
                                                        :./test
#include <stdio.h>
void main(){
int i;
int big=0;
printf("enter number : ");
scanf("%d",&i);
while(1){
printf("enter number : ");
if(i>0) {if(i>big) big=i;}
else {printf("largest number entered : %d\n",big);
return;}
scanf("%d",&i);}
}

Write a console program that prompts the user for an integer.

Q: Mini-program: Write a console program that prompts the user for an integer. As long as the user keeps entering positive integers, continue prompting for the next integer. Once the user enters an integer of 0 or less, report the largest integer that was entered and end the program.

Solution:


import java.util.ArrayList;
import java.util.Scanner;

public class LargestNumber

{
public static void main(String args[])
{
int ending=0;
ArrayList<Integer> list=new ArrayList<Integer>();/* declare arrylist to store the value*/
int value=1;
while(value>0)
{
System.out.println("Please Enter the number");/* promt the user to give the number*/
Scanner in=new Scanner(System.in);
value=in.nextInt();/* store the entered value */
ending =value;
if(value>0){/* check if the value is greater than zero than only it will store*/
list.add(value);
}
 
}
int max=0;
for(int i=0;i<list.size();i++)
{
if(list.get(i).intValue()>max)
max=list.get(i).intValue();
 
}
System.out.println("----------------------------------------");
System.out.println("largest number is=");/* print the largest number*/
System.out.println(max);
}
}

Design and implement a reusable program that takes any standard Shape and returns a Rectangle that completely incloses the Shape.

Q: Design and implement a reusable program that takes any standard Shape and returns a Rectangle that completely incloses the Shape. I expect you to write a class that defines a method to handle a shape. Let's name the class as MyClass and the method as reusable. For simplicity, consider only Rectangle 2 cap D.Double and Line2D.Double whenever you need to show s Shapes in your answer. You don't have to concern about drawing shapes for this question. Your job is to answer the subquestions (a) through (d). API is on the last page. Identify required classe(s) and interface(s) to solve the problem and draw the corresponding class diagram to depict their relationship. Include specific Shapes in your class diagram. Implement the reusable program MyClass. Write a tester that calls the reusable method with two different specific Shape objects. public class Tester {public static void main (String [] args) {//your work goes here.}} Briefly explain how polymorphism is used in the execution of the reusable method.

Solution:
 
a) Rectangle and Circle both are Shape.
So we selected Rectangle and Circle as Classes and Shape as interface for both, becouse shape has common funtionality fot both.
Classes Rectangle is a Shape and Circle is a Shape so both has "IS A" relationship with Shape
b)Implematation =>
//================== Shape.java ===========================//
public interface Shape {
   public double getArea();
   public double perimeter();
}
//========================== Rectangle.java ===========================//
public class Rectangle implements Shape {
   private double height;
   private double length;
 
   public Rectangle() {
     
   }
   public Rectangle(double h,double l) {
       height = h;
       length = l;
   }
 
   @Override
   public double getArea() {
       return height*length;
   }
   @Override
   public double perimeter() {
       return 2.0d*(height+length);
   }
   public double getHeight() {
       return height;
   }
   public void setHeight(double height) {
       this.height = height;
   }
   public double getLength() {
       return length;
   }
   public void setLength(double length) {
       this.length = length;
   }
}
//============================= Circle.java ========================//
public class Circle implements Shape {
   private double radius;
   final private double PI = 22.0d/7.0d;
   public Circle() {
     
   }
   public Circle(double r) {
       radius = r;
   }
   @Override
   public double getArea() {
       return PI*radius*radius;
   }
 
   @Override
   public double perimeter() {
       return 2.0*PI*radius;
   }
   public double getRadius() {
       return radius;
   }
   public void setRadius(double radius) {
       this.radius = radius;
   }
   public double getPI() {
       return PI;
   }
}
c) Test Program
//============================= ReusableTest.java==================================//
public class ReusableTest {
   public static void main(String[] args) {
       Shape[] shapes = new Shape[2];
       shapes[0] = new Rectangle(40.0d, 30.0d);
       shapes[1] = new Circle(20.0d);
       for(int i = 0;i<2;i++){
           System.out.println("Shape "+i+" Area :"+shapes[i].getArea());
           System.out.println("Shape "+i+" Perimeter :"+shapes[i].perimeter());
       }
   }
}
d)
We have careated Shape refrence variable and storing the object of circle and rectangel
by using shape only we are calling method area and perimeter but actual method is called from respective objcet only, so that is the example of run time polimorphysm

Friday, 6 December 2019

What will the following code fragment printout?

What will the following code fragment printout? 
String myString = "Java": System.out.println(myString.toUppercase() + "or" + myString): 
 A. java or Java 
B. Java or Java 
C. JAVA or JAVA 
D. JAVA or Java

Solution:

 
D (JAVA or Java)

The below program has two varints the first variant which converts all characters in the string to upper case and second variant takes locale as argument and converts into upper case

Write a complete Java program for the following questions

Q. Write a complete Java program for the following questions:    
         Write a program that print the following on the screen.
Java
Java Java
Java Java Java
Java Java Java Java
Java Java Java Java Java

Solution:

 
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       int i,j;
       for(i=0;i<5;i++)
       {
           for(j=0;j<=i;j++)
               System.out.print("JAVA ");
             
           System.out.println();
       }
   }
}

Southridge Company incurred the following costs related to its purchase of a new assembly line

1. Southridge Company incurred the following costs related to its purchase of a new assembly line: Purchase cost: Php 9,435,000 (including Php 435,000 freight and purchase taxes)
Recoverable purchase taxes: Php 960,000
Irrecoverable purchase taxes: Php 870,000
Installation of assembly line: Php 975,000
Training of employees: Php 195,000
Estimated repair and maintenance costs over useful life: Php 500,000
What is the amount to be recognized as asset related to the assembly line?
a.
Php 11,280,000
b.
Php 9,450,000
c.
Php 9,645,000


Solution:

Answer: b) Php 9,450,000
Note:
1.As per IAS 16-Property Plant & Equipment, Employee Training cost will not be part of Assets capitalization. unless those cost is directly associated to bring assets to required condition & use as intended by management.
2. Repair & Maintenance cost can not be part assets capitalization..

Php
Cost of New assembly    9,435,000.00
Less:Recoverable Tax     (960,000.00)
Add:Installation cost        975,000.00
Asset to be Recognized 9,450,000.00

Wednesday, 4 December 2019

Write a program that has a declaration in main() to store the string "Vacation"

Q: Write a program that has a declaration in main() to store the string "Vacation" i near in an array named message. Also, add a function call to display() that accepts message in an argument named strng and then displays the contents of message by using pointer notation *(strng + i), modify the display() function to use the expressions *strng rather than *(strng + i). The program I compiled from this question is listed below, I am struggling with placements of notations on the latter part of the question.

#include <iostream>
using namespace std;

int main(){
void dispstr(char*);
char str[] = "Vacation";

display(str);
return 0;
}

void display(char* ps)
{
while( *ps )
cout << *ps++;
cout << endl;
}

Solution:

 #include <iostream>
using namespace std;

int main(){
void dispstr(char*);
char str[] = "Vacation";

display(str);
return 0;
}

void display(char* ps)
{
while( *ps )
cout << *ps++;
cout << endl;
}

Write a program that has a declaration in main() to store the string Vacation

Q: Write a program that has a declaration in main() to store the string Vacation is near in an array named message. Include a function call to display () that accepts message in an argument named string and then displays the contents of message by using the pointer notation *(strng + i).
Then modify the display() function written to use the expression *strng rather than *(strng +i) to retrieve the correct element.


Solution:

#include <iostream>

using namespace std;

void display(char* string)
{
for(int i=0; i<strlen(string); i++)
cout << *(string+i);
}

void display2(char* string)
{
int len = strlen(string);
for(int i=0; i<len; i++)
{
cout << *string;
string++;
}
}

int main()
{
char message[50] = "Vacation is near";


display(message);
cout << endl;
display2(message);
return 0;