C++ Programming

C++ Programming


Demonstrates the use of structure in C++

Posted: 20 Apr 2013 08:21 AM PDT

#include <iostream> using namespace std; int main() {         // Defining a structure         struct PersonalData         {                 char *FirstName;                 char *LastName;                 char *Birthday;  // in the format of 12/27/1978                 int  PhoneNum;         }; // don't forget the ending ";"         // Declaring a variable of type PersonalData        

Launch notepad using C++

Posted: 20 Apr 2013 07:38 AM PDT

#include <iostream.h> #include <windows.h>  int main(void) { cout<<"Explorer will launch.\n"<<endl; /*replace with the path to your explorer.exe*/ system("h:\\windows\\explorer.exe"); return 0; }

If - Else example

Posted: 20 Apr 2013 07:36 AM PDT

#include <iostream.h> #include <math.h> int main() { double radius; //get user input cout<<"Please enter the radius : "; cin>>radius; //act on user input if(radius < 0.0) cout<<"Cannot have a negative radius"<<endl; else cout<<"The area of the circle is "<<3.1416 * pow(radius,2)<<endl; return 0; }

A short string demonstration

Posted: 20 Apr 2013 07:24 AM PDT

#include <iostream> #include <string> using namespace std;   int main() {   string str1("A");   string str2("B");   string str3("O");   string str4;     str4 = str1;   cout << str1 << "\n" << str3 << "\n";     str4 = str1 + str2;   cout << str4 << "\n";     str4 = str1 + " to " + str3;   cout << str4 << "\n";     if(str3 > str1)      cout << "str3 > str1\n";   if(str3 == str1+str2)    

A Simple if Statement

Posted: 20 Apr 2013 07:22 AM PDT

This program illustrates a simple if statement. It reads in two integers and prints out a message on the screen according to their values. #include <iostream> using namespace std; int main() {   int a, b;   cout << "Enter first number: ";   cin >> a;   cout << "Enter second number: ";   cin >> b;   if(a < b)  cout << "First number is less than second.\n";   return 0; }


Post a Comment