C++ Return Addition with Integers

email me
#include "stdafx.h"
#include<iostream>
#include<string>

using namespace std;

int main()
{
	unsigned int userInput;
	unsigned long long addition = 0;
	string sum = "0";

	cout << "Enter an integer: ";
	cin >> userInput;

	for (int i = 1; i <= userInput; ++i)
	{
		addition += i;
		std::string intCast = std::to_string(i);
		sum = sum + "+" + intCast;
	}

	sum.replace(0, 2, "");//if you don't want to see 0+

	cout << "\nSum of " << sum << "=" << addition;
	cin.get();

	cin.get();

	return 0;
}

C++ Return Factorial with Integers

email me
#include "stdafx.h"
#include<iostream>
#include<string>

using namespace std;

int main()
{
	unsigned int userInput;
	unsigned long long factorial = 1;
	string sum = "0";

	cout << "Enter an integer: ";
	cin >> userInput;

	for (int i = 1; i <= userInput; ++i)
	{
		factorial *= i;
		std::string intCast = std::to_string(i);
		sum = sum + "*" + intCast;
	}

	sum.replace(0, 2, "");//if you don't want to see 0+

	cout << "\nFactorial of " << sum << "=" << factorial;
	cin.get();

	cin.get();

	return 0;
}

C++ Return Factorial

email me
#include "stdafx.h"
#include<iostream>

using namespace std;

int main()
{
	unsigned int userInput;
	unsigned long long factorial = 1;

	cout << "Enter an integer: ";
	cin >> userInput;	

	for (int i = 1; i <= userInput; ++i)
	{
		factorial *= i;
	}

	cout << "Factorial of " << userInput << " = " << factorial;
	cin.get();

	cin.get();

	return 0;
}

SCCM – IP Addresses

email me

A dirty little secret of Microsoft, and why you don’t see IP address columns in the SCCM console, is that MS stores all the IP addresses of a machine into a single row, into an array. So, when viewed, you’ll see 1-6 (or more) IP addresses all crammed together. Not great.

 

Here are some common methods for dealing with IP addresses. I normally just run the queries directly on the SQL DB, but you can also use SCCM Reporting and SCCM Queries under Monitoring.

 

SCCM REPORT TO LIST IP ADDRESSES – LITE VERSION

select distinct
A.Name0,c.IPAddress0,
D.IP_Subnets0
from v_R_System A
inner join v_FullCollectionMembership B on A.ResourceID=B.ResourceID
Inner join v_GS_NETWORK_ADAPTER_CONFIGUR C ON A.ResourceID=C.ResourceID
Inner Join v_RA_System_IPSubnets D ON A.ResourceID=D.ResourceID
where CollectionID=@COLLID and C.IPEnabled0='1'
group by A.Name0,c.IPAddress0 ,D.IP_Subnets0
order by A.Name0,c.IPAddress0 ,D.IP_Subnets0

 

SCCM REPORT TO LIST IP ADDRESSES – FULL VERSION

SELECT distinct
CS.name0 as 'Server Name',
OS.Caption0 as 'OS',
CU.Manufacturer0 as 'Manufacturer',
CU.Model0 as 'Model',
RAM.TotalPhysicalMemory0/1024 as [RAM (MB)],
processor.Name0 as 'Processor',
BIOS.ReleaseDate0 as 'BIOS Manufacture Date',
OS.InstallDate0 as 'OS Install Date',
IP.IP_Addresses0 AS 'IP Address'

from
v_R_System CS
FULL join v_GS_PC_BIOS BIOS on BIOS.ResourceID = CS.ResourceID
FULL join v_GS_OPERATING_SYSTEM OS on OS.ResourceID = CS.ResourceID
FULL join V_GS_X86_PC_MEMORY RAM on RAM.ResourceID = CS.ResourceID
FULL JOIN v_GS_PROCESSOR Processor on Processor.ResourceID=CS.ResourceID
FULL join v_GS_SYSTEM_ENCLOSURE SE on SE.ResourceID = CS.ResourceID
FULL join v_GS_COMPUTER_SYSTEM CU on CU.ResourceID = CS.ResourceID
join v_RA_System_IPAddresses IP on IP.ResourceID = CS.ResourceID

WHERE CS.Operating_System_Name_and0 LIKE '%nt%server%'
AND IP.IP_Addresses0 NOT LIKE '192.168%'
AND IP.IP_Addresses0 NOT LIKE '172.10%'
AND IP.IP_Addresses0 NOT LIKE '%:%'
AND IP.dhcpenabled0 = 0

group by
CS.Name0,
OS.Caption0,
CU.Manufacturer0,
CU.Model0,
RAM.TotalPhysicalMemory0,
BIOS.ReleaseDate0,
OS.InstallDate0,
Processor.Name0,
BIOS.ReleaseDate0,
IP.IP_Addresses0
Order by CS.Name0

 

IP ADDRESSES SINGLE COLUMN

Select Distinct

SD.Name0,

IP.IpAddress0

From v_Gs_System SD

Join v_Gs_Network_Adapter_Configur IP

On SD.ResourceId = IP.ResourceId

Where IP.DefaultIPGateway0 Is Not NULL

And IP.IPAddress0 Is Not NULL

And IP.IPAddress0 <> '0.0.0.0'

Order By SD.Name0

 

DISTINCT ADDRESSES, multiple rows

SELECT v_RA_System_ResourceNames.Resource_Names0 AS [Resource name],
v_RA_System_IPAddresses.IP_Addresses0 AS [IP Address]
FROM v_RA_System_MACAddresses INNER JOIN
v_RA_System_ResourceNames ON v_RA_System_MACAddresses.ResourceID = v_RA_System_ResourceNames.ResourceID INNER JOIN
v_RA_System_IPAddresses ON v_RA_System_MACAddresses.ResourceID = v_RA_System_IPAddresses.ResourceID

SINGLE IP ADDRESS
SELECT DNSHostName0 AS [NetBIOS Name],
CASE WHEN IPAddress0 like '%,%' THEN left(IPAddress0,CHARINDEX(',',IPAddress0)-1)
ELSE IPAddress0 END AS [IP Address]
FROM v_GS_NETWORK_ADAPTER_CONFIGUR
WHERE ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPAddress0 not like 'fe%')
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPAddress0 IS NOT NULL)
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPAddress0 not like '169.254.%')
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].DefaultIPGateway0 IS NOT NULL)
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPEnabled0 = '1')

 

SCCM QUERY RETURN IPs TO ONE COLUMN

select Name, IPAddresses,
LastLogonUserDomain,
LastLogonUserName,
ResourceType,
NetbiosName,
ClientType
from sms_r_system
where Client = 1 and SMS_R_System.Name = SMS_R_System.Name

C++ Input and Output

email me

Compiled in Visual Studio 2017.

#include "stdafx.h"
#include<stdio.h>
#include<cstdio>
#include<iostream>

#define size 50

using namespace std;

class card {

    char title[size];
    char author[size];
    int num_book;

public:
    void store();
    void show();
};

void card::store()
{
    cout << "Enter Title: "; std::cin.getline(title,size); //cin >> title;

    cout << "Enter Author: "; std::cin.getline(author,size); //cin >> author;

    cout << "Enter number of copies: "; cin >> num_book;
	getchar();
	// if char std::cin.getline(num_book, 3);

}

void card::show()
{

	std::cout << "\nTitle: " << title << "  \nAuthor: " << author << "\nCopies: " << num_book;

}

// ENTRY POINT - GOVERNOR
int main()
{
    int choice;

    card b1, b2;

    cout << "{{{ Library Management System }}}\n\n";

// INPUT
    cout << "\nStore book-1 information\n";
    b1.store();

    cout << "\nStore book-2 information\n";
    b2.store();

// OUTPUT
    cout << "\n\nInformation of book-1";
    b1.show(); 

    cout << "\n\nInformation of book-2";
    b2.show();
    cin.get();

}

Screenshot

Java – Prime Numbers with User Input

email me

Compiled and tested here: http://www.browxy.com/

import java.util.Scanner;

class Main {
public static void main(String[] args) {

Scanner reader = new Scanner(System.in);
System.out.println("Enter a number: ");
int N = reader.nextInt(); // user input.

// Array
// 0 - prime, 1 - composite
int[] arr = new int[N + 1];
arr[0] = arr[1] = 1;

// loop from 2 to square root of N
for (int i = 2; i <= Math.sqrt(N); i++) {

// check if prime
if (arr[i] == 0) {

// add all factors of i to composite numbers to N
for (int j = i * i; j <= N; j += i) {
arr[j] = 1;
}
}
}

// Print all positions for which fields are not reset
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 0) {
System.out.print(i + ", ");
}
}
}
}

C++ Basic Math

email me

Compiled in Visual Studio 2017.

#include "stdafx.h"
#include<iostream>
#include<string>

using namespace std;

// METHOD 1
void messages (void)
{
	// initialize strings
	string xString1;

	// output message
	xString1 = "Doing basic math. \n\nLet's try some math in the console.\n";
	cout << xString1 << endl;

}

// METHOD 2
void addition (void)
{

	// initialize variables
	int xInt1, xInt2, xResult;

	xInt1 = 9;
	xInt2 = 4;

	// do some addition
	xResult = xInt1 + xInt2;		

	// do some casting
	std::string castInt1 = std::to_string(xInt1);
	std::string castInt2 = std::to_string(xInt2);

	std::string output = "\nAddition: ";
	output += castInt1 + " + " + castInt2 + " = " + std::to_string(xResult);

	cout << output << endl;

}

// METHOD 3
void subtraction(void)
{

	// initialize variables
	int xInt1, xInt2, xResult;

	xInt1 = 9;
	xInt2 = 4;

	// do some subtraction
	xResult = xInt1 - xInt2;

	// do some casting
	std::string castInt1 = std::to_string(xInt1);
	std::string castInt2 = std::to_string(xInt2);

	std::string output = "\nSubtraction: ";
	output += castInt1 + " - " + castInt2 + " = " + std::to_string(xResult);

	cout << output << endl;

}

// METHOD 4
void multiplication(void)
{

	// initialize variables
	int xInt1, xInt2, xResult;

	xInt1 = 9;
	xInt2 = 4;

	// do some multiplication
	xResult = xInt1 * xInt2;

	// do some casting
	std::string castInt1 = std::to_string(xInt1);
	std::string castInt2 = std::to_string(xInt2);

	std::string output = "\nMultiplication: ";
	output += castInt1 + " x " + castInt2 + " = " + std::to_string(xResult);

	cout << output << endl;

}

// METHOD 5
void wait(void)
{
	string xString2;

	// wait for keypress
	xString2 = "\n\nPress any key to continue...";
	cout << xString2 << endl;
	cin.get();

}

// ENTRY POINT - PROGRAM GOVERNOR
int main()

{
	// call messages
	messages();

	// call addition
	addition();

	// call subtraction
	subtraction();

	// call multiplication
	multiplication();

	// call wait
	wait();

}

Notes

std::to_string

string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);
Convert numerical value to string

Returns a string with the representation of val.

The format used is the same that printf would print for the corresponding type:

type of valprintf
equivalent
description
int"%d"Decimal-base representation of val.
The representations of negative values are preceded with a minus sign (-).
long"%ld
long long"%lld
unsigned"%u"Decimal-base representation of val.
unsigned long"%lu
unsigned long long"%llu
float"%f"As many digits are written as needed to represent the integral part, followed by the decimal-point character and six decimal digits.
inf (or infinity) is used to represent infinity.
nan (followed by an optional sequence of characters) to represent NaNs (Not-a-Number).
The representations of negative values are preceded with a minus sign (-).
double"%f
long double

C++ Hello World

email me

Compiled in Visual Studio 2017.

#include "stdafx.h"
#include<iostream>
#include<string></string></iostream>

using namespace std;

// METHOD 1
void messages (void)
{
// initialize strings
string xString1;

// output message
xString1 = "Hello World! \n\nWelcome to console apps.\n\n";
cout << xString1 << endl;

}

// METHOD 2
void wait (void)
{
string xString2;

//output message
xString2 = "Press any key to continue...";
cout << xString2 << endl;

// wait for keypress
cin.get();

}

// ENTRY POINT - PROGRAM GOVERNOR
int main()

{
// call messages
messages();

// call wait
wait();

}

JavaScript – Key Codes

email me

The keyCode property returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.

Key codes represent an actual key on the keyboard.

An example of key codes in action


function mykey() { document.onkeydown = function(){
switch (event.keyCode){
// KILL ALT F4
case 18 :
event.returnValue = false;
event.keyCode = 0;
return false;
case 115 :
event.returnValue = false;
event.keyCode = 0;
return false;

//F5 button
case 116 :
event.returnValue = false;
event.keyCode = 0;
return false;

//ESC button
case 27 :
event.returnValue = false;
event.keyCode = 0;
return false;

//r
case 82 :
if (event.ctrlKey){
event.returnValue = false;
event.keyCode = 0;
return false;
}
}
}
}

 

Key Codes

 Key  Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
 Key  Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
 Key  Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222

Assembly – Even or Odd Number

email me

< back

Return whether a number is even or odd.

Tested in emu8086 emulator.  Learning: 1  2  3  4  5  6  book

.DATA
 MSG1 DB 10,13,'Enter number: 

 

Screenshot



 MSG2 DB 10,13,'Result: Even

 

Screenshot



 MSG3 DB 10,13,'Result: Odd

 

Screenshot



DATA ENDS
DISPLAY MACRO MSG
 MOV AH,9
 LEA DX,MSG
 INT 21H
ENDM

.CODE
 ASSUME CS:CODE,DS:DATA
 START:
  MOV AX,DATA
  MOV DS,AX
  DISPLAY MSG1
  MOV AH,1
  INT 21H
  MOV AH,0
 CHECK: 
  MOV DL,2
  DIV DL
  CMP AH,0
  JNE ODD
 EVEN:
  DISPLAY MSG2
  JMP DONE
 ODD:
  DISPLAY MSG3
 DONE:
  MOV AH,4CH
  INT 21H
CODE ENDS
END START

 

Screenshot

Assembly – Multiplication

email me

< back

Perform multiplication of two numbers.

Tested in emu8086 emulator.

See addition and subtraction.  Learning: 1  2  3  4  5  6  book

.MODEL SMALL
.STACK 200H
.DATA
 NUM1 DB ?
 NUM2 DB ?
 RESULT DB ?
 MSG1 DB 10,13,"Enter NUM1: $"
 MSG2 DB 10,13,"Enter NUM2: $"
 MSG3 DB 10,13,"Result: $"
ENDS

.CODE
ASSUME DS:DATA CS:CODE
START:
 MOV AX, @DATA
 MOV DS, AX
 LEA DX, MSG1
 MOV AH, 9
 INT 21H
 MOV AH, 1
 INT 21H
 SUB AL, 30H
 MOV NUM1, AL
 LEA DX, MSG2
 MOV AH, 9
 INT 21H
 MOV AH, 1
 INT 21H
 SUB AL, 30H
 MOV NUM2, AL
 MUL NUM1
 MOV RESULT, AL
 AAM
 ADD AH, 30H
 ADD AL, 30H
 MOV BX, AX
 LEA DX, MSG3
 MOV AH, 9
 INT 21H
 MOV AH, 2
 MOV DL, BH
 INT 21H
 MOV AH, 2
 MOV DL, BL
 INT 21H
 MOV AH, 4CH
 INT 21H
ENDS
END START

 

Screenshot