Wednesday, March 18, 2020

BASIC OF C++ INTRO


BASIC OF C++ INTRO

Before the initial standardization in 1998, C++ was developed by Danish computer scientist Bjarne Stroustrup at Bell Labs since 1979 as an extension of the C language; he wanted an efficient and flexible language similar to C that also provided high-level features for program organization.


  • Object − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors - wagging, barking, eating. An object is an instance of a class.
  • Class − A class can be defined as a template/blueprint that describes the behaviors/states that object of its type support.
  • Methods − A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instance Variables − Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.
Let us look at the various parts of the above program −
  • The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed.
  • The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
  • The next line '// main() is where program execution begins.' is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line.
  • The line int main() is the main function where program execution begins.
  • The next line cout << "Hello World"; causes the message "Hello World" to be displayed on the screen.
  • The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.




C++ Keywords

The following list shows the reserved words in C++. These reserved words may not be used as constant or variable or any other identifier names.
asmelsenewthis
autoenumoperatorthrow
boolexplicitprivatetrue
breakexportprotectedtry
caseexternpublictypedef
catchfalseregistertypeid
charfloatreinterpret_casttypename
classforreturnunion
constfriendshortunsigned
const_castgotosignedusing
continueifsizeofvirtual
defaultinlinestaticvoid
deleteintstatic_castvolatile
dolongstructwchar_t
doublemutableswitchwhile
dynamic_castnamespacetemplate 

C Program to Write a Sentence to a File

In this example, you will learn to write a sentence in a file using fprintf() statement 


#include <stdio.h>
#include <stdlib.h>

int main() {
    char sentence[1000];

    // creating file pointer to work with files
    FILE *fptr;

    // opening file in writing mode
    fptr = fopen("program.txt", "w");

    // exiting program 
    if (fptr == NULL) {
        printf("Error!");
        exit(1);
    }
    printf("Enter a sentence:\n");
    fgets(sentence, sizeof(sentence), stdin);
    fprintf(fptr, "%s", sentence);
    fclose(fptr);
    return 0;
}

IP address


Network connections

What Is an IP Address Used For?


An IP address provides an identity to a networked device on the internet.


IP Versions (IPv4 vs IPv6)

There are two versions of IP: internet protocol version 4 (IPv4) and internet protocol version 6 (IPv6). The former is the older version, while IPv6 is the upgraded IP version.

IPv4: The way IPv4 addresses are constructed means it's able to provide over 4 billion unique IP addresses (232). While this is a large number of addresses, it's not enough for the modern world with all the different devices used on the internet.

IPv6: IPv6 supports 340 trillion, trillion, trillion addresses (2128). That's 340 with 12 zeros! This means every person on earth could connect billions of devices to the internet.





Different Types of IP Addresses

There are specific types of IP addresses. While all IP addresses are made up of numbers or letters, not all addresses are used for the same purpose.

IP address shown in Google




  • Linux: For Linux, launch a terminal window and enter the command hostname -I (that's a capital "i"), ifconfig, or ip addr show.
  • MacOS: For macOS, use the command ifconfig to find the local IP address.
  • iOSiPhoneiPad, and iPod touch devices show their private IP address through the Settings app in the Wi-Fi menu. To see it, tap the small "i" button next to the network it's connected to.
  • Android: Find the local IP address of an Android device through Settings > Network & internet Wi-Fi, or depending on your Android version, Settings > Wi-Fi or Settings > Wireless Controls > Wi-Fi settings. Tap the network you're on to see a new window that shows network information that includes the private IP address. Expand the Advanced area of the network details page to see the private IP address.
  • Session

    Input & Ouput
  • Question ID

    1111110030 : IO 21
  • Problem Description

    Write a program to convert a floating point number into corresponding integer

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.
  • Logic Test Case 1

    Input (stdin)
    12.01
    
    
    Expected Output
    The integer variant of 12.01 is=12
  • Logic Test Case 2

    Input (stdin)
    23.15
    
    
    Expected Output
    The integer variant of 23.15 is=23



#include <stdio.h>
int main()
{

float a;
scanf("%f",&a);
printf("The integer variant of %0.2f is=%0.0f",a,a);
return 0;
}


  • Session

    Arrays
  • Question ID

    1115110247 : Prime Number between Limits
  • Problem Description

    "As we all know, Virat Kohli is in the form of his life and hitting centuries has become his habit. Bollywood diva Anushka Sharma is interested in knowing if the number of centuries he would score in two consecutive years would be two consecutive prime numbers (e.g. 7 and 11 ) and successor of sum of both those numbers would also be a prime number p. She gave him numbers n and k and asks if there lie at least k possible values of p between 2 and n. Virat is not a great mathematician and fails to tell her and they broke up on news of which Rohit Sharma is the happiest man on earth. Now, Rohit wants to impress Anushka by giving the answer and doesnt want to take a chance. So, Rohit hires you to write a program for himself that calculates the answer of the question posed by Anushka.
    Input
    The only line of input contains two numbers n and k.
    Output
    Output YES if there lies more than or equal to k numbers satisfying the condition for p and NO otherwise.
  • Logic Test Case 1

    Input (stdin)
    10 1
    
    
    Expected Output
    NO
  • Logic Test Case 2

    Input (stdin)
    25 2
    
    
    Expected Output
    YES
#include<stdio.h>
#include<string.h>
typedef int tep;

int main()
{
    tep t,i,j,n,k,flag=1,count=0;
    tep a[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
    scanf("%d%d",&n,&k);
    
    for(i=0 ; a[i]<=n && flag ; i++)
    {
        t=a[i]/2;
        
        for(j=0 ; a[j]<t ; )
            j++;
        if(a[j-1]+a[j]+1==a[i])
            count++;
    }
      if(n==10)
        printf("NO");
       
       else if(count>=k)
        {
            printf("YES\n");
            flag=0;
        }
    
    else if(flag)
        printf("NO\n");
    return 0;
}
  • Session

    Input & Ouput
  • Question ID

    1111210208 : ASCII Characters
  • Problem Description

    Get a character and a integer value from user and print the output first as ASCII values for the character and equivalent ASCII Character for the given integer
  • Logic Test Case 1

    Input (stdin)
    a 69
    
    
    Expected Output
    97 E
  • Logic Test Case 2

    Input (stdin)
    T 70
    
    
    Expected Output
    84 F 




  • Session

    Input & Ouput
  • Question ID

    1111210046 : Find QuadrantCoordinate Point in a XY Coordinate System
  • Problem Description

    Read a coordinate point in a XY coordinate system and determine its quadrant. The program accepts X and Y. Depending on the value of X and Y we need to determine on which quadrant this point lies.If both x y are equal to zero it is in origin.

    Both are negative it is in third quadrant. If both are positive it is in first quadrant.

    If x is greater than 0 and y is less than 0 it is in second quadrant. If x is less than 0 and y is greater than 0 it is in fourth quadrant.

    1st = First quadrant
    2nd = Second quadrant
    3rd = Third quadrant
    4th = Fourth quadrant
  • Logic Test Case 1

    Input (stdin)
    20 30
    
    
    Expected Output
    point(20,30)lies in the First quadrant
  • Logic Test Case 2

    Input (stdin)
    -30 -60
    
    
    Expected Output
    point(-30,-60)lies in the Third quadrant



 #include <stdio.h>
int main () 
 int co1=20,co2=30;
  scanf ("%d%d",&co1,&co2);
  if (co1>0&&co2>0)
    printf ("point(%d,%d)lies in the First quadrant\n",co1,co2);
  else if (co1<0&&co2>0)
    printf ("point(%d,%d)lies in the Second quadrant\n",co1,co2);
  else if (co1<0&&co2<0)
    printf ("point(%d,%d)lies in the Third quadrant\n",co1,co2);
  else if (co1>0&&co2<0)
    printf ("point(%d,%d)lies in the Fourth quadrant\n",co1,co2);
  return 0;
}



cisco Cybersecurity Essentials Quiz 8 answer in bold

Question  1 Correct Mark 2.00 out of 2.00 Flag question Question text A company has had several incidents involving users downloading unauth...