Saturday, 11 April 2015

Code for Creating a New Node in C++ (Algorithm Style)

struct Node{
int data;
Node *link;
};

void main(){
Node *start;
start = NULL;
start = new Node;
start->data=2;
start->link=NULL;
cout<<start->data;
}


Explanation:


  • Line 1 to 4: We have created a new structure named Node (we will create Nodes of our linked list using this structure).
  • Line 6: Start of the main() function.
  • Line 7: We have declared a pointer variable, named: start (Note this pointer variable can only point to things which are type of Node).
  • Line 8: We have made "start", a "NULL" (just to make sure that it contains no dummy values).
  • Line 9: "new Node" means create a new Node,
    and "start = new Node" means "start variable is pointing to the newly created node".
  • Line 10: place "10" inside the "data" member of that node, which start is pointing to.
  • Line 11: make "link" member of the node "NULL"
  • Line 12: just output "data" part of the node, which start is pointing to.


Blogger Tricks

Friday, 11 July 2014

A Program That Calculates Fee Collected From Class

Problem

Write a program that gets input of total number of students in a class and then asks for the fee collected per student. It displays total fee collected from the class.
Note: Problem forwarded to us by "Ali Aftab".

Input 3-Digit Number and Output Each Digit on Separate Line

Problem

The problem is to input a 3 digits number from the user. And then break that number into digits and show each digit on separate line. This problem should be solved using C++ (C Plus Plus) programming language.
Note: The problem was sent to me by my friend "Ali Aftab".

Monday, 10 March 2014

Chapter 1: Engineering Numerical Analysis


getline: Another Method of Taking Input in C Plus Plus

In previous lessons we have learn that the keyword cin is used to get input from the user. But I want to tell you something about cin keyword that is very important to know. The keyword cin separates the words or "group of characters differentiated by spaces". It only keeps the first group of characters (or first word) and ignores the rest of the characters coming after the space.

Wednesday, 5 February 2014

A Program that Finds Minimum Number using Loop

Problem:

Write a program that inputs the series of 20 numbers and displays the minimum value.

Solution:

Here is the code that gets input of 20 numbers and displays the minimum value using for loop.

A Code to Display Alphabets using For-Loop

Problem:

Write a program to display alphabets from A to Z using for-loop.

Solution:

Here is the code that displays alphabets from A to Z using for-loop: