Skip to main content

Posts

Showing posts from July, 2018

Cpp STL Map

Map Example 1 #include <iostream> #include <map> #include <string> using namespace std; int main() {        map < string , string > provinces = { { "ON" , "Ontario" },{ "BC" , "British Columbia" },{ "QC" , "Quebec" }};               cout << "Size of the map is " << provinces.size() << endl;        for ( auto && p : provinces)        {               cout << p.first << "\t" << p.second << endl;        }        system( "pause" );        return 0; } Example 2 #include <iostream> //#include <vector> //#include <list> //#inclu...

Cpp STL Set

The Standard Template Library Common Classes Set Example 1: Create a set that holds string values. Print the size. Using a for each loop print all the elements to the console screen. #include <iostream> #include <set> #include <string> using namespace std; int main() {        set < string > strList = { "john" , "Paul" , "Jesse" , "Patty" , "John" , "john" };        cout << "Size of the list is " << strList.size() << endl;        for ( auto && s : strList)        {               cout << s << endl;        }        system( "pause" );        return 0; }

Cpp STL List

The Standard Template Library Common Classes List Example 1: Create a list that holds string values. Print the size and first and last elements. Finally using a for each loop print all the elements to the console screen, #include <iostream> #include <list> #include <string> using namespace std; int main() {        list < string > strList = { "john" , "Paul" , "Jesse" , "Patty" };        cout << "Size of the list is " << strList.size() << endl;        cout << "The first item in the list is " << strList.front() << endl;        //The following are not allowed as list does not allow random access        //cout << "The second item in the list is " << strList[1] << endl; //using substring     ...

Cpp STL Vector

The Standard Template Library Common Classes Vector Example 1: Create a vector that holds string values. Print the size and first, second, third and last elements. Finally using a for each loop print all the elements to the console screen. #include <iostream> #include <vector> #include <string> using namespace std; int main() {        vector < string > strVector = { "john" , "Paul" , "Jesse" , "Patty" };        cout << "Size of the Vector is " << strVector.size() << endl;        cout << "The first item in the vector is " << strVector.front() << endl;        cout << "The second item in the vector is " << strVector [ 1 ] << endl; //using substring        cout << "The second item in the vector is " <...

Swing Lab 2

Swing Lab 2 1. In this lab, we will use IntelliJ Wysiwyg editor, to create an application as shown below: 2. Click File → New → Project. Click Next → Next → Enter “JavaCalculater as the project name → Click ‘Finish’. 3. Right click on the src folder → New → GUI Form. Enter CalcForm as Form name and click OK. 4. Select JPanel in the Component Tree. Make sure that the layout is set to GridLayoutManager. 5. Add component to JPanel as shown in the screenshot above. Set the properties of the JComponents as required. 6. Within the Calcform.java class create a main method() using the code given below: public static void main(String[] args) {   JFrame frame = new JFrame( "JavaCalc" );   frame.setContentPane( new CalcForm(). panelmain );   frame.setVisible( true );   frame.setSize( 400 , 300 );   frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ); } 7. Run the program.  ...

Day 6 - Introduction to NoSQL Database and HBase

Topics: Introduction to NoSQL Database and HBase  Reading List Apache HBase Reference Guide -   http://hbase.apache.org/book. html Apache HBase Guide -  https://www.cloudera.com/ documentation/enterprise/ latest/topics/hbase.html How to create example tables in HBase -  http://gethue.com/hadoop- tutorial-how-to-create- example-tables-in-hbase/

Perl Exercise 10

Pattern matching =~ operator is used for matching pattern, pattern is given within // as shown below: $sentence = “the quick brown fox”; if ($sentence =~ /fox/){ print(“found the fox”); } else { print (“fox not found”); } Output: Found the fox Splitting a sentence into words A sentence can be split into words and stored in an array as shown below: $sentence = “the quick brown fox”; @words = split(/ /, $sentence); The above code does not work very well when you have multiple spaces in between words. The extra space can be considered as words. This problem can be solved using the following: $sentence = “the quick   brown fox”; @words = split(/ +/, $sentence); Using the +  after a space matches one or more number of spaces. Question 1 Create a perl program asks the user to input a message. The program then should count the number of words in the message and print words and word count to the console screen. Enter a messag...

Day 5 - Hive built-in functions

Topics: Hive built-in functions Reading List Tutorials/Documentation Apache hive Built-In functions -   https://data-flair.training/blogs/hive-built-in-functions/ Hive build-in functions -  https://support.treasuredata.com/hc/en-us/articles/360001450748-Hive-Built-in-Functions Cheat Sheet: How To Work with Hive Functions in Hadoop -  https://hortonworks.com/blog/cheat-sheet-working-with-hive-functions/ HiveQL: Data Definition -  https://www.oreilly.com/library/view/programming-hive/9781449326944/ch04.html

IO Lab 1

In this lab we learn about streams. Stream is a sequence if data that is read or written from beginning to end. Depending on if the data is read or written, it is called an InputStream or OutputStream. 1.        Create a new project. 2.        Create a new directory called “files” in the root folder. 3.        Download the following file and copy to the files directory: https://docs.oracle.com/javase/tutorial/essential/io/examples/xanadu.txt FileReader, Try-with-resource statement, AutoClose interface. 4.        Create an input stream to read a text file in your computer. FileReader fRead = new FileReader(“xanadu.txt”); 5.        You will have to surround the about line with try-with-resources statement. This closes fileReader in case of an exception.   Take a look at the AutoClose Interface. 6.    ...