Hacking Equipments | C/C++ Coding | Updates:: Did you tried Our Online ? AdobePhotoshop |
Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

[ Problem ] Calculating Digital Root Input from Binary File

0 Comments

Problem :


Given a well-formed (non-empty, fully valid) string of digits, let the integer N be the sum of digits. Then, given this integer N, turn it into a string of digits. Repeat this process until you only have one digit left. Simple, clean, and easy: focus on writing this as cleanly as possible in your preferred programming language.

------------------------------------------------------------------

Input Description

------------------------------------------------------------------

As a crude form of hashing function, Lars wants to sum the digits of a number. Then he wants to sum the digits of the result, and repeat until he have only one digit left. He learnt that this is called the digital root of a number, but the Wikipedia article is just confusing him.

Can you help him implement this problem in your favourite programming language?

It is possible to treat the number as a string and work with each character at a time. This is pretty slow on big numbers, though, so Lars wants you to at least try solving it with only integer calculations (the modulo operator may prove to be useful!).

------------------------------------------------------------------

Formal Inputs & Outputs
Input Description

A positive integer, possibly 0.
Output Description

An integer between 0 and 9, the digital root of the input number.

Sample Inputs & Outputs



Sample Input

31337

Sample Output

8, because 3+1+3+3+7=17 and 1+7=8
Challenge Input

1073741824

Challenge Input Solution

?
Note :
GIve the user option to either input the number as well or read input from a binary file in binary mode.


Solution :


Code :

#include <iostream>
#include <fstream>
#include <conio.h>
#include <stdio.h>

using namespace std;

int main(void){  
	long int n,m;
	int c=0,a=0;
	printf("Take Input from binary File (y/n) :=:");
	char ch=getch();
	while(1){
		if(ch=='Y'||ch=='y'){
			char r[25];
			cout<<"\n\n\nEnter The Name of the File :=:"; cin>>r;
			printf("\n\n Write New Value or Read Previous ? (W/R) :=:"); 
			char chi=getch();
			if(chi=='W'||chi=='w'){
				int num;
				cout<<"\n\nEnter The Number to store :=: "; cin>>num;
				ofstream of(r,ios::binary|ios::out);
				of.write((char*)&num,sizeof(&num)); // writing
				of.close();
			}
			ifstream in(r,ios::binary|ios::in);
			if(!in){
				cout<<"\n\n\t\t::Wrong Input of file::\n";
			}
			else{
				in.read((char*)&n,sizeof(&n)); // then reading what is written :p
			}
			in.close();
			break;
		}
		else if(ch=='N'||ch=='n'){

			cout<<"\n\n\nEnter Your Number :=:"; cin>>n; cout<<"\n\n";
			break;
		}
		else{
			continue;
		}
	}
	if(n<=9){
		cout<<"Invalid Entry Kindly Number Should be greater than 9\n\n";
		exit(1);
	}
	m = n;
	while(m){
		c+=(m%10);
		m/=10;
	}
	m = c;
	while(m){
		a+=(m%10);
		m/=10;
	}
	cout<<"\n\n\nHere is the Digital Root of Num :"<<n<<": :=:"<<a<<"\n\n";
	return 0;
}


Logic & Implementation :


  • Used Concept of Binary File I/O , in.read((char *)& (Here is Your Variable/identifier) ,  sizeof(& (Here is Your Variable/identifier) )) . same with in.write , it will convert your each bit( character  ) in binary while storing .
  • Digital root is already explained.
  • Use printf() when you are using getch() or getche() , printf() is in stdio.h and getch() and getche() is in conio.h 
  • When Stream directories Like fstream or iostream will be used Do not use as .h at end in c++ Use using namespace std; as i've used .
  • Keep In Mind { Everything inside this will be destroyed after it complete execution called Scope } .



[Solutions] Variable - Operator & Expressions Assignment 1

0 Comments
These are solved questions for the assignment number 1 of variable - operator - expressions ,

Q1: Write a Program to print "SALAM WORLD" on Screen.

Code:

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

 printf("SALAM WORLD");

 return 0;

}

Logic & Note: 

  • Used Printf() function to print from directory of stdio.h 



Q2 :Write a Program to Print the following Output using only 1 statement.

Student               Marks
1                        100
2                        50
3                        30

Code :

#include <iostream.h>
void main(){
 cout<<"Student\t\tMarks\n1\t\t100\n2\t\t50\n3\t\t30\n";
}

Logic & Note: 

  •  \t , \n , \r , \b these are some commonly used Escape Sequences. e.g \n is used to go to next line and \t used for 1 tab . 
  • cout<< it is a stream printer . 


Q3 :Write a Code to display a Number 4569.988463 upto 2 decimal places on screen , the number should be displayed as : 4569.98 (* The program should not contain more than 2 statements)

 Code :

#include <stdio.h>
void main(){
 float f=4569.988463;
 printf("This Is The Number :=: %0.2f",f);
}

Logic & Note: 

  • Used void main to save a statement for return 0; 
  • Now basically %f is Format specifier used to display in printf function with double quotes, as i've used as %0.2f i am indicating it that round off mantissa up to 2 digits , don't care about the 0.2 0 part because it is stretched up to the number length but if you give it greater the rest will results to print space character. 
Q4 : Write a program to print Area of a circle.


Code :

#include <iostream.h>
int main(){
 double r,area; // similar to float but can hold upto 14 decimal places , 8 bytes 
 cout<<"Enter Radius :=:";
 cin>>r;
 cout<<"\n";
 area=r*r;
 cout<<"Area Of The Circle :=:"<<area<<"\n\n";
 return 0;
}

Logic & Note: 

  • Area= radius^2 . 
  • double is my favourite datatype , i use it instead of float. 
  • cout<< used to putting string/number to console , cin>> getting input from console . 



Q5 :Write A program to get two numbers from user and Print their sum on screen.

Code :

#include <iostream.h>
int main(){
 double a,b,sum; // numbers can be float or integers

 cout<<"Number 1 :=:"; cin>>a; cout<<"\n";
 cout<<"Number 2 :=:"; cin>>b; cout<<"\n";

 sum=a+b;

 cout<<"Sum :=:"<<sum<<"\n\n";

 return 0;
}

Logic & Note: 

  • sum= a+b for adding , & numbers can be integer/float/double so don't take a risk i've said two numbers !! not integers or floats 
  • Use inputting as i've used in a single line it will give a good impact/and less line of code. 


Q6:Write a program the get temperature in centigrade and Convert it into fahrenheit .

Code :

#include <iostream.h>
int main(){
 double cen,fah; // Numbers can be float or integers

 cout<<"Temperature in Centigrade :=:"; cin>>cen; cout<<"\n";

 fah = (5/9)*cen+32; // According to DMAS , multiplication 1st then addition so no brackets used

 cout<<"Temperature in Fahrenheit :=:"<<fah<<"\n\n";

 return 0;
}

Logic & Note : 

  •  fahrenheit = ((5/9)*Centigrade)+32 , used to find keep in mind that DMAS rule will always apply when performing calculation but parenthesis part will always run first because it have greater precision, for more precision info visit : Here 


Q7:Write a program That inputs number and Show its ASCII value.

Code :

#include <iostream.h>
int main(){
 char c;
 int d;

 cout<<"Enter Character :=:"; cin>>c; cout<<"\n";

 d = c; 

 cout<<"Value in ASCII :=:"<<d<<"\n\n";

 //cout<<"Value in ASCII :=:"<<(int)c<<"\n\n";

 return 0;
}

Logic & Note : 

  • As c contains a character and each character have ASCII value basically when saved in memory, 
  • i've assigned character to integer it will always perform function with its ASCII value so , i got ascii value. 
  • There are More flexible ways of doing it is type casting ,, putting data type in parentheses as i've done (int) . in last line. 


Q8:Write a Program To input two values and Swap Values of that two variables and Print them .

Code :

#include <iostream.h>
int main(){
 int a,b,temp;

 cout<<"Enter Value a :=:"; cin>>a; cout<<"\n";
 cout<<"Enter Value b :=:"; cin>>b; cout<<"\n";

 temp=a;
 a=b;
 b=temp;

 cout<<"Value a :=:"<<a<<"\n\n";
 cout<<"Value b :=:"<<b<<"\n\n";
 
 return 0;
}

Logic & Note: 

  • What i've done is just used another variable temp , assigned value of 'a' to 'temp' , and now i've saved value of 'a' now i can change it , now assigning 'b' to 'a' , and finally assigning 'temp' to 'b' , which is actually 'a' . 


Q9 :Write a Program which get number and Print the Number is +ve or -ve on screen. (*using ternary operator)

Code :

#include <iostream.h>
int main(){
 int Num;

 cout<<"Enter Your Number :=:"; cin>>Num; cout<<"\n";
 
 (Num>0)? cout<<"::Number is Positive::\n": cout<<"::Number is Negative::\n";

 return 0;
}

Logic & Note : 

  • if the number will be greater than zero it is positive otherwise it is negative. 
  • ternary operator have following syntax: (condition)?run if true:run if false; variable=(condition)?run if true:run if false do not use ; with middle part its an error . 
Q10:Write a Program which get number and print whether it is +ve or -ve and it is even or odd .(*using ternary operator) .

Code :

#include <iostream.h>
int main(){
 int Num;

 cout<<"Enter Your Number :=:"; cin>>Num; cout<<"\n";
 
 (Num>0)? cout<<"::Number is Positive::\n": cout<<"::Number is Negative::\n";
 (Num%2==0)? cout<<"::Number is Even::\n" : cout<<"::Number is Odd::\n";

 return 0;
}

Logic & Note : 

  • if a number remainder with 2 will be zero then it will be even otherwise if 1 then it is odd. (% is reminder sign)


Corrections & errors are accepted kindly share , More Assignments coming soon :p

Starting With C++ And Writing Our First Program

0 Comments
We will get started With Installation of Compiler Basically,

What is C++ Compiler?

A C++ compiler is itself a computer program which only job is to convert the C++ program from our form to a form the computer can read and execute. The original C++ program is called the “source code”, and the resulting compiled code produced by the compiler is usually called an “object file”.

Before compilation the preprocessor performs preliminary operations on C++ source files. Preprocessed form of the source code is sent to compiler.

After compilation stage object files are combined with predefined libraries by a linker, sometimes called a binder, to produce the final complete file that can be executed by the computer. A library is a collection of pre-compiled “object code” that provides operations that are done repeatedly by many computer programs.


We'll be Start Using MS Visual C++ v 6.0 , You'll Get It From Here . it'll looks like



1. Now type sample program on Editor , For Example



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

     printf("Salam World");
     
     return 0;
}



2. Click on Compile button on the top right corner or press CTRL + F7

click Yes


Again Yes



Again Yes



3. Click on Run button (Red question mark) or press Ctrl+F5


4. If there is no error output will be displayed on User Screen.



Before we begin to learn to write meaningful programs in C++ language, You Should Cover the topics i have mentioned in Beginners to advance movement from Sources Like (google these terms) :

But for advance techniques HC team will also share you some techniques regarding c++ . See You In Our Next Article In Which We'll Make Our First set of Assignment.

[Learning] Beginners to Advance Gateway C/C++

1 Comments

We Are Going to Cover The Following Topics.

From The Start


Need of Programming Language, Source Code, Object code, C++ Compiler, Preprocessor, Linker, Using Turbo C++ Compiler .or Ms Visual C 6.0 .


Difference between C and C++ 


C as good practicing approach , beginners best Choice, C and C++ some major difference , Syntax Differences, Advanced Features of C++ .


Note : We'll Carry On Using C++ , where C have very short differences Which We Will Discuss in Our Articles.

C++ Basics Building Blocks


C++ Character Set, Tokens, Keywords, Identifiers, Literals, Integer constants, Character constants, Floating constants, Strings constants, Escape Sequence, Punctuators, Operators


Data Handling in C++


Basic data types, Variables, Input/Output (I/O), Type conversion, type casting, Constants, Structure of C++ Program, Comments

Operators


Arithmetic operators, Relational operators, Logical operators, Unary operators, Assignment operator, Compound Assignment Operators, Conditional operator

Flow Of Control


Conditional Statements, if statement, if else , nested if, switch statement, Looping statement, while loop, do-while loop, for loop, Jump Statements, goto, break, continue

Library Function (all types)


#Include Directive, Mathematical Functions, Character Functions, String Functions, Console I/O functions, General purpose standard library functions, Some More Functions

Functions(MOST USED)

Prototyping, defining and calling a function, actual parameters and formal parameters, return type of a function, call by value, call by reference, inline function, default argument, global variable local variable

Array


Declaration, Initialization of 1-D Array, Referring to array elements, using loop to input array from user, array as Parameter, traverse, Read, Linear Search, Binary Search, Bubble, Insertion Sort, Selection Sort, Merge

2-D Array


read a 2-D array, display content of a 2-D array, sum of two 2-D arrays, multiply two 2-D arrays, sum of rows & sum of columns of 2-D array, sum of diagonal elements of square matrix, transpose of a 2-D array

String


Declaration, Initializing, Reading strings, Printing strings, cin, gets(), cout, puts() ,simplify the output and input,counting number of characters in string, count number of words, length of string, copy contents of string, concatenate, compare string , Conversion of String To character Array . Array To String Conversion

Structures


Defining a structure, Declaring Variables of Type struct, Accessing of its data members, Initialization of structure variable,Nested structure, typedef, Enumerated data type, #define, Macros , Some Confusing Question/Answers

Pointer


C++ Memory Map, Defining Pointer Variable, Pointer Arithmetics, Pointers and Arrays, Pointers and strings, Pointers to Structures, Dynamic memory, Memory Leak, Self Referential Structure 

Advanced Learning


OOP Concepts


Procedural Paradigm, Object Oriented programming, Object, Class, Data Abstraction, Encapsulation, Modularity, Advantages of Object oriented programming

Data File Handling (Text Files)


File, Stream, Text file, Binary file, ofstream, ifstream, fstream class, Opening a file, Closing file, Input and output operation, File pointer and their manipulation , How To Use It Flexibly in Program

Classes & Objects


Classes and Objects, declaring a class, private members, protected members, public members, Example of a class

Constructors


Constructor, Types of Constructor, Default Constructor, Para-meterized Constructor Copy Constructor, Constructor overloading, Destructor

Inheritance


Inheritance, Base Class, Derived Class, Single Inheritance, Multiple, Hierarchical, Multilevel and Hybrid Inheritance, Visibility Mode, Containership, Overriding of function in inheritance, Virtual Base Class

Data File Handling( Binary File)


Program to write, read, display, count number of characters, words,lines in text file. In binary file write, display records, search, delete and modify a record

More Will Be Coming Soon..

Kindly Get the articles names and Search the whole description from CPP Forum www.cplusplus.com

If Some Guru Programmers Want to write learning articles of c/c++ then just send it From Here.

Beginners Guide C++ for Game Programming 3rd edition

2 Comments


One of the recommended pdf by me to , learn about the game programming in c++ , many others ebooks coming soon.




Download :


Link1     or     Link2     or     Link3     or     Link4     or     Link5    

 or       [MIRROR]     


Regards,
h4ck3r jutt

Hacking Unix/Xenix Begginers Guide

0 Comments
******************************************************************************
A BEGINNERS GUIDE TO:

* * H A C K I N G * * 

* * U N I X * *

* * BY : H4ck3r Jutt * * 

* *(NOTE: THIS Article i have written by taking different ideas from different sources. ) * *

WRITTEN: 2011
******************************************************************************

in the following,


All References Made To The Name Unix, May Also Be Substituted To The Xenix Operating System. 


Brief History: 

Back In The Early Sixties, During The Development Of Third Generation Computers At Mit, 

A Group Of Programmers Studying The Potential Of Computers, Discovered  Their Ability Of Performing Two Or More Tasks Simultaneously. Bell Labs, Taking Notice Of This Discovery, 

Provided Funds For Their Developmental Scientists To Investigate Into This New Frontier. After About 2 Years Of Developmental Research, 

They Produced An Operating System They Called "Unix". 


Sixties To Current: 

During This Time Bell Systems Installed The Unix System To Provide Their Computer Operators With The Ability To Multitask So That They Could Become More Productive, And Efficient. One Of The Systems They Put On The Unix System Was Called "Elmos". Through Elmos Many Tasks (I.E. Billing,And Installation Records) Could Be Done By Many People Using The Same Mainframe. 

Note: Cosmos Is Accessed Through The Elmos System. 

Current: Today, With The Development Of Micro Computers, Such Multitasking Can Be Achieved By A Scaled Down Version Of Unix (But Just As Powerful). Microsoft,Seeing This Development, Opted To Develop Their Own Unix Like System For The Ibm Line Of Pc/Xt's. Their Result They Called Xenix (Pronounced Zee-Nicks). Both Unix And Xenix Can Be Easily Installed 

On Ibm Pc's And Offer The Same Function 

(Just 2 Different Vendors[Names] ). 

Note: Due To The Many Different Versions Of Unix (Berkley Unix, Bell System Iii, And System V The Most Popular) Many Commands Following May/May Not Work. I Have Written Them In System V Routines. 

Unix/Xenix Operating Systems Will Be Considered Identical Systems Below. 

How To Tell If/If Not You Are On A Unix System: 

Unix Systems Are Quite Common Systems Across The Country. 

Their Security Appears As Such: 


Login; (Or Login;) 

Password: 


When Hacking On A Unix System It Is Best To Use Lowercase Because The Unix System Commands Are All Done In Lowercase

Login: 


Is A 1-8 Character Field. It Is Usually The Name (I.E. Joe Or Fred) Of The User, Or Initials (I.E. J.Jones 
Or F.Wilson). Hints For Login Names Can Be Found Trashing The Location Of The Dial-Up (Use Your Cn/A To Find Where The Computer Is). 

Password: Is A 1-8 Character Password Assigned By The Sysop Or Chosen By The User. 

Common Default Logins 

                      
Login:                       Password: 

Root                        Root,System,Etc.. 

Sys                          Sys,System 

Daemon                   Daemon 

Uucp                       Uucp 

Tty                          Tty 

Test                        Test 

Unix                       Unix 

Bin                         Bin 

Adm                      Adm 

Who                      Who 

Learn                     Learn 

Uuhost                  Uuhost 

Nuucp                   Nuucp 




If You Guess A Login Name And You Are Not Asked For A Password, And Have Accessed To The System, Then You Have What Is Known As A Non-Gifted Account. 

If You Guess A Correct Login And Password, Then You Have A User Account. And, If You Guess The Root Password, Then You Have A "Superuser" Account. 

All Unix Systems Have The Following Installed To Their System: 

Root, Sys, Bin, Daemon, Uucp, Adm 

Once You Are In The System, You Will Get A Prompt. Common Prompts Are: 





But Can Be Just About Anything The Sysop Or User Wants It To Be. 

Things To Do When You Are In: Some Of The Commands That You May Want To Try Follow Below: 

Who Is On (Shows Who Is Currently Logged On The System.) 

Write Name (Name Is The Person You Wish To Chat With) 

To Exit Chat Mode Try Ctrl-D

Eot = End Of Transfer. 

Ls -A (List All Files In Current Directory.) 

Du -A (Checks Amount Of Memory Your Files Use;Disk Usage) 

Cd\Name (Name Is The Name Of The Sub-Directory You Choose) 

Cd\ (Brings Your Home Directory To Current Use) 

Cat Name (Name Is A Filename Either A Program Or Documentation Your Username Has Written) 

Most Unix Programs Are Written In The C Language Or Pascal Since Unix Is A Programmers' Environment. 

One Of The First Things Done On The System Is Print Up Or Capture (In A Buffer) The File Containing All User Names And Accounts. This Can Be Done By Doing The Following Command: 

Cat /Etc/Passwd 

If You Are Successful You Will A List Of All Accounts On The System. It Should Look Like This: 

Root:Hvnsdcf:0:0:Root Dir:/:
Joe:Majdnfd:1:1:Joe Cool:/Bin:/Bin/Joe
Hal::1:2:Hal Smith:/Bin:/Bin/Hal
The "Root" Line Tells The Following Info :
Login Name=Root
Hvnsdcf = Encrypted Password
0 = User Group Number
0 = User Number
Root Dir = Name Of User
/ = Root Directory 

In The Joe Login, The Last Part "/Bin/Joe " Tells Us Which Directory Is His Home Directory (Joe) Is. 


In The "Hal" Example The Login Name Is Followed By 2 Colons, That Means That There Is No Password Needed To Get In Using His Name. 


Conclusion: I Hope That This File Will Help Other Newbies Unix Hackers Obtain Access To The Unix/Xenix Systems That They May Find. There Is Still Wide Growth In The Future Of Unix, So I Hope Users Will Not Abuse Any Systems (Unix Or Any Others) That They May Happen Across On Their 
Journey Across The Electronic Highways Of America. There Is Much More To Be Learned About The Unix System That I Have Not Covered. They May Be Found By Buying A Book On The Unix System (How I Learned) Or In The Future I May Write A Another Version Of It..

That Will Be 2012 Version Inshallah!! Kindly Comment Rate And Share.
 

About Admin

I am a pro-programmer of C++ ,php i can crack some softwares and am a web desighner .I AM also on .


| Solve Byte © 2011 - 2016. All Rights Reserved | Back To Top |