Working with Array and Vectors Using STL in C++

sudhir sharma
Updated on 17-Jul-2020 10:56:51

411 Views

Array and vectors are very important data structures in competitive programming for solving problems. And the STL (Standard Template Library) in c++ programming provide some functions to perform operations of arrays and vectors.Let’s see some of these functions in action, Finding sum, Min and Max of the array/vector − In STL there are function that helps you to find the sum, max, and min of the array/vector. Functions with there function, Finding sumaccumulate(startIndex, endIndex, initialSum)Greatest element of the array/vecto*max_element(startIndex, endIndex)Smallest element of array/vector*min_element(startIndex, endIndex)Program to perform operations on array −Example Live Demo#include using namespace std; int main(){    int array[] ... Read More

Working with Tmux Session

sudhir sharma
Updated on 17-Jul-2020 10:52:40

455 Views

Tmux is a terminal multiple for Unix OS. It provides multiple terminal sessions to its users. It is used when we are using cloud-based services (like Azure, AWS) for the creation of separate terminals for different remote users.While working with web services, one needs to create an EC2 instance on the webserver provided by the company to work on it by creating a session.Now, let’s see the steps of working on a UNIX (Ubuntu) webserver.Step 1 − Write/copy the IP address of your AWS console and download the key file from the console. You will get these from your vendor ... Read More

Print a Particular Line from a File in C using Bash Script

sudhir sharma
Updated on 17-Jul-2020 10:50:06

380 Views

In this program, we are given a file name text.txt. Our task is to print a particular line from the file.For this there are multiple methods in bash script, they are awk, sed, head.Syntax$> awk ‘{if(NR==LINE_NUMBER) print $0}’ filename $> sed -n LINE_NUMBERp filename $head -n LineNumber filename | tail - n + LINE_NUMBERCode to print a specific line in bash programming from file text.txt.Using awk$> awk ‘{if(NR==5) print $0}’ text.txtUsing sed$>sed -n 5p text.txtUsing head$head -n 5 filename | tail - n + 5

Display File Contents Like More Utility in Linux using C

sudhir sharma
Updated on 17-Jul-2020 10:48:40

283 Views

Here, we will write a C program that will display the contents of a file page by page as displayed in Linux using the more command.This program will show a specific number of lines on the screen first and then wait for the user to hit enter to move to the next page i.e. next set of n lines.For displaying the content of the file like this we will open the file and print its contents. And maintain a counter for new lines in the file. When this counter reaches n, we will read a key pressed by the user ... Read More

C Program That Won't Compile in C++

sudhir sharma
Updated on 17-Jul-2020 10:33:40

293 Views

Here, we will write some c programs that won’t compile in c++. Though c++ is considered as a successor of c that has all its features and has compatibility with c code there are some programs that won’t compiler or given a compilation error when compiled with c++ compiler.A list of some of the C programs that won’t compile in c++ are −Call to a function before declaration − In c++, function call before declaration gives compilation error. But this works fine in c.Example Live Demo#include int main(){    printHello();    return 0; } void printHello(){    printf("TutorialsPoint"); }OutputTutorialsPointUsing typecasted ... Read More

Best Way to Add an Event in JavaScript

AmitDiwan
Updated on 17-Jul-2020 09:12:58

159 Views

The best way to add an event to any element is to use the addEventListener() method.Following is the code to add an event in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 20px;       font-weight: 500;       color: rebeccapurple;    } Adding event in JavaScript CLICK HERE Click on the above button to increment the font size of above text    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {       resEle.style.fontSize = "34px";    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Decrement a Date by 1 Day in JavaScript

AmitDiwan
Updated on 17-Jul-2020 09:11:04

286 Views

Following is the code to decrement a date by 1 day in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 20px;       font-weight: 500;       color: rebeccapurple;    } JavaScript program to decrement a date by 1 day Decrement Click on the above button to decrement the date by one day    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let date = new Date();    sampleEle.innerHTML = date;    document.querySelector(".Btn").addEventListener("click", () => {       date.setDate(date.getDate() - 1);       resEle.innerHTML = "New Date = " + date;    }); OutputThe above code will produce the following output −On clicking the ‘Decrement’ button −

Find Keys of a Hash in JavaScript

AmitDiwan
Updated on 17-Jul-2020 09:09:10

447 Views

Following is the code for finding keys of a hash in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Find keys of a hash in JavaScript DISPLAY Click on the above button to display the hash keys    let resEle = document.querySelector(".result");    let obj = {       firstName: "Rohan",       lastName: "Sharma",       age: 22,    };    document.querySelector(".Btn").addEventListener("click", () => {       resEle.innerHTML += "object keys are " + Object.keys(obj);    }); OutputThe above code will produce the following output −On clicking the ‘DISPLAY’ button −

Validate Decimal Numbers in JavaScript

AmitDiwan
Updated on 17-Jul-2020 09:02:49

555 Views

Following is the code to validate decimal numbers in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Validate decimal numbers in JavaScript CHECK Click the above button to check if a valid decimal number is entered or not    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {       var str = document.querySelector(".num").value;       var regex = /^[-+]?[0-9]+\.[0-9]+$/;   ... Read More

Remove Child Node in HTML using JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:58:54

219 Views

Following is the code to remove a child node in HTML using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Removing a child node in HTML using JavaScript Cow Lion Tiger Buffalo CLICK HERE Click the above button to remove the first list element from the above list    let resEle = document.querySelector(".result");    let animalList = document.querySelector(".animal");    document.querySelector(".Btn").addEventListener("click", () => {       animalList.removeChild(animalList.childNodes[0]);       animalList = animalList;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Advertisements