Wednesday, 15 April 2020

C++ Program - Calculate Simple Interest

Q: Write a program which accept principle, rate and time from user and print the simple interest.

Solution:

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
 int p,r,t,i;
 cout<<"Enter Principle : ";
 cin>>p;
 cout<<"Enter Rate : ";
 cin>>r;
 cout<<"Enter Time : ";
 cin>>t;
 i=(p*r*t)/100;
 cout<<"Simple interest is : "<<i;
 return 0;
}
  Screenshot:
 

C++ Question - Farenheit to Celcius

Q: Write a program which accept temperature in Fahrenheit and print it in centigrade.
Solution:

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
 float F,C;
 cout<< "\nEnter temperature in Farenheit : ";
 cin>>F;
 C=5*(F-32)/9;
 cout<<"Temperature in celcius is : "<<C;
 return 0;
}

Screenshot:

C++ Program - Sum of Two Numbers

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
 int a,b,c;
 cout<< "\nEnter first number : ";
 cin>>a;
 cout<<"\nEnter second number : ";
 cin>>b;
 c=a+b;
 cout<<"\nThe Sum is : "<<c;
 return 0;
}

Screenshot: 

Escape Sequence Example in C++

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
 cout<<"subject " <<"\tmarks"<<"\nmathematic\t"
 <<90<<"\ncomputer\t"<<77<<"\nchemistry\t"<<69;
 return 0;
}

Screenshot: 

C++ Hello World Program

Q: Write a program to print HELLO WORLD on screen.
Solution:

#include<iostream>
using namespace std;

int main(int argc, char *argv[])
{
 cout<<"Hello world";
 return 0;
}

Screenshot:

Sunday, 2 February 2020

MySQL Multiple Choice Question

1. Which of the following is not one of the top databases in use today?
(a) Amazon CloudIt
(b) Microsoft SQL Server
(c) Oracle
(d) MySQL
(e) MongoDB
Solution:
A (Amazon CloudIt)

Explanation : Microsoft SQL server, Oracle, and MySQL are relational databases. MongoDB is non relational databases. Amazon CloudIt is not a database.
2. MySQL is free to use as a back-end database for a website.
(a) True
(b) False

Solution:
 True

  Explanation : MySQL is free to use as a back-end database for a website.

3. MySQL uses which TCP/IP port by default?
Solution:
MySQL uses 3306 TCP/IP port by default.

4. MySQL is primarily a relational database based on SQL.
(a) True
(b) False
Solution:
True

Explanation : MySQL is primarily a relational database based on Structured Query Language (SQL).

5. Which of the following is correct about this command: mysql -u root -p?
(a) Installs MySQL for the first time
(b) Starts the MySQL Service in Linux
(c) Starts the MySQL Service in Windows
(d) Configures MySQL to like rootbeer
(e) Connects to MySQL on localhost
Solution:
E) Connects to MySQL on localhost

Explanation : 'mysql -u root -p' command is used to connect to MySQL on localhost. To connect to remote host we have to use -h option. 'mysql -h <remote-ip> -u <user> -p
6. The MySQL Configuration file for Windows is:
(a) my.cnf
(b) mysql.prop
(c) my.ini
(d) my.conf
(e) mysql.conf
Solution:
c (my.ini)
7. The MySQL Configuration file for Linux is:
(a) my.cnf
(b) mysql.prop
(c) my.ini
(d) my.conf
(e) mysql.conf
Solution:
a (my.cnf)

Explanation : we can define most of MySQL's configuration parameters in the my.cnf file which is located in /etc/mysql folder.

Sunday, 26 January 2020

How to monitor changes to an SQL server table

How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is .NET and C#.

I'd like to be able to support any SQL Server 2000 SP4 or newer. My application is a bolt-on data visualization for another company's product. Our customer base is in the thousands, so I don't want to have to put in requirements that we modify the third-party vendor's table at every installation.

By "changes to a table" I mean changes to table data, not changes to table structure.

Ultimately, I would like the change to trigger an event in my application, instead of having to check for changes at an interval.

The best course of action given my requirements (no triggers or schema modification, SQL Server 2000 and 2005) seems to be to use the BINARY_CHECKSUM function in T-SQL. The way I plan to implement is this:

Every X seconds run the following query:

SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*))
FROM sample_table
WITH (NOLOCK);
And compare that against the stored value. If the value has changed, go through the table row by row using the query:
SELECT row_id, BINARY_CHECKSUM(*)
FROM sample_table
WITH (NOLOCK);
And compare the returned checksums against stored values.

Solution:
CHECKSUM command:
 SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) FROM sample_table WITH (NOLOCK);
That will return the same number each time it's run as long as the table contents haven't changed.