Search This Blog

Pages

Saturday, January 29, 2011

LabTask1.3

--------------------
/*By Subodh Dahal*/

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


#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

int main()
{
int roll[5],age[5];
char name[5][20],check;
int i=0;

Wednesday, January 26, 2011

LabTask1.2

/*WAP to find smallest and largest number from array using DMA with new and delete operator. After destroying its memory with delete operator what will happen? Comment on your results.*/

#include<iostream.h>
int main()
{
int *p=new int[20];

Friday, January 21, 2011

Initial of Lab Task 1

----------------------------------------------------------
Written by Sagar Giri

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


OBJECT: BASIC PROGRAMMING ON C++

THEORY:

Output operator
cout<<

            The identifier cout is a predefined object that represents the standard output stream in C++. The operator << is called the insertion or put to operator. In inserts (or sends) the contents of the variable on its right to the object on its left. If string represents a string variable then the following statement will display its contents.

            cout<<string;

E.g.:

Monday, January 17, 2011

LabTask1.1

#include<iostream.h>
int main()
{
float fahrenheit, celcius;
cout<<"Please input the temperature in Fahrenheit: ";
cin>>fahrenheit;
celcius=5/9*(fahrenheit-32);
cout<<"\nThe temperature in Celcius is: "<<celcius;
return 0;
}

Wednesday, January 12, 2011

Storing numbers dynamically n displaying them


/*
 * storing_numbers_dynamically_n_displaying_them.cpp
 *
 *  Created on: Jan 12, 2011
 *      Author: bgsudeep
 *      
 *      Here "dynamically" means a pointer with delete option
 *      We should have to store the numbers using a pointer in main function and at the end of the
 *      program we should have to clean or delete the memory used by the program.
 */

#include<iostream.h>
int main()
{
int *p=new int[10];
int i;

Swapping Two Values using call by reference


/*
 * swapping_values_using_call_by_reference.cpp
 *
 *  Created on: Jan 12, 2011
 *      Author: bgsudeep
 */

#include<iostream.h>
void swap(int &, int &);
int main()
{
int a, b;
cout<<"Please input two numbers separated by space or an enter key: "<<endl;
cin>>a>>b;
swap(a,b);
cout<<"Your swapped number is: "<<endl<<a<<" and "<<b;
return 0;
}
void swap(int &pa, int &pb)
{
int temp;
temp=pa;
pa=pb;
pb=temp;
}

Return by Reference

/*
* Return_by_reference.cpp
*
* Created on: Jan 12, 2011
* Author: bgsudeep
* This program is suitable when we need to give some value for the greater value among two values.
*/

#include<iostream.h>
int &max(int &a, int &b);
int main()
{
int x,y;
cout<<"Please input two numbers: "<<endl;
cin>>x>>y;
max(x,y)=10;
cout<<"x= "<<x; //Here if you put the value of x which is less than y then it will displays the value of x.
//If you put the value of x which is greater than y then it will displays the value 10.

return 0;
}
int &max(int &a, int &b)
{
if (a>b)
return a;
else
return b;
}

Tuesday, January 11, 2011

Review of C

For this program, credit goes to my friend Suroj Karmacharya (SKAMMA)
/*Write a program that removes all the extra spaces, tables or any other wild or special characters from a given sentence and make a simple English sentence ended with (.).
* Example: Input: I like $^ C++ very much
* Output: I like C++ very much.*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{