Posts

File handling with C++ Programming

Image
Learn File handling with the following sample code You are to write a program that reads in lines of input using scanf or cin, and file redirection, process the data, and then output the results using printf or cout. This means you can use C or C++ style I/O as is your personal preference. Name your file lab1assignment.cpp. Failure to name the file correctly may lead to a grade of zero. The data file used in the example is available at: ~dmk0080/public/1040/labs/one.or in the Cavans assignment. Use the file named "transactiondata Use command line redirection to execute as in ./a.out angle bracket transactiondata" to compile use g++ labassignment1.cpp to create the executable file a.out The Data: Each line of th named "transactione data file begins with an 'e', 'c', or 't'. Lines beginning with 'e' will have an integer employee ID and an employee name. Lines beginning with 'c' will have an integer custo

Pandas for Data Analysis: How to get Data from APIs

Image
It is much easier to create Data Frame objects from data we have from files such as csv, excel, list or JSON , but how do we obtain data from online sources such as APIs ? That is what we will learn from this short blog. Requirements We need “requests” and “pandas” packages to pull data from APIs sources. The requests package will be used to make API request while pandas is used to create Data Frame. On our Jupiter notebook, we add the following imports To test the aforementioned imports and how it pulls data from API source, we will request data from the USGS API. These are data recorded every day that relates to earthquake. We will pull data for the last 30 days up to yesterday. As such, we’ll need datetime package. Thus, all imports are as follows: Now that we’ve got all the imports ready, we can start pulling data from USGS API. With requests package, we will be able to make GET request to the USGSAPI and obtain JSON payload. The data we are trying to obtain were record

Build a Shopping List Application with ArrayList in Java

Image
ArrayList What’s an ArrayList? Oracle documentation defines an ArrayList as a resizable array that implements List interface. ArrayList comes with a ton of methods that allow manipulation of the array. Some of the methods applicable in ArrayLize include, size, add, get, set, isEmpty and more. I will show how some of the methods work with using code. When defining an ArrayList, it is important to specify the type because ArrayList holds objects. Above,we have specified the type as String. As such, the ArrayList defined will only be able to hold elements of type String. Adding Items to ArrayList ArrayList provides add method that can be used to add items to ArrayList. The method can be called using ArrayList variable defined earlier. In our case, we have created a method and passed an item that will be added to ArrayList using add method. See the following screenshot: : Print items in an ArrayList I mentioned earlier that ArrayList provides several methods to manipulate d

Sort arrays in descending order using Java

Image
For us to understand arrays in Java , we’ll write a small program that sorts a list of integers in descending order. The program uses arrays, and it is expected to sort the values in descending order- from the highest to the lowest value. For instance, if the user of the program passes in these values, 1,10,24,56,90,71,2. The values should be sorted in a descending order, meaning that the output should be 90,71,56,24,10,2,1. The program will be set up in a way that numbers to be sorted are read from the keyboard. In addition, the program implements the following methods, sortIntegers – to sort an array of integers and return a new array that contains sorted numbers. The printArray method to print sorted integers and getIntegers to return an array of numbers entered from the keyboard. getIntegers method The method takes one integer value which determines the size of an array and uses for-loop to get integer values from the keyboard and returns an array of integers. Here is a sc

Learn how Python allow us to Manipulate Strings

Image
In many cases, text is one of the most common forms of data in a program. All programming languages have to handle strings in one way or another. Python makes it easy to handle data with strings. You can concatenate two strings using + operator, convert a letter uppercase or lowercase, remove spacing in string, check if string contains an alphabet character and more. Examples string literals “That’s a nice car.” “Today is Jane’s birthday.” We can assign any of string literals above to a variable and print them on an interactive shell. We can also change a string to lower or uppercase using some of the useful methods such as lower() and upper(). If we want to confirm if a string is in lowercase or uppercase, we can use islower() or isupper() functions. We can confirm this on interactive shell, see below. If we have a list of strings that we want to join, join() can be used. We can also split a string using split() method. I will write a code showing how the split meth

Hangman Game With Python

Image
  Problem and Solution  Here are the instructions of what is expected of this game: You have been assigned a task to implement the Hangman game. In hangman, one player chooses a secret word and the other player guesses letters. Each time the second player guesses a correct letter, all instances of that letter in the secret word are revealed. If the second player guesses a letter that is not in the word, then a portion of the hangman is drawn. The game ends once the entire hangman is drawn or the second player guesses all the letters that are in the word. NOTE: The second player has 7 guesses to guess the correct word After each incorrect guess, the pieces of the hangman are drawn in the following order; Rope, Head, Torso, Left arm, Right arm, Left leg, Right leg At the beginning of the game, the first player should be asked to enter the secret word The letters in the secret word should be displayed as '?' until the user guesses them  At the beginning of each round you should di