Wednesday, June 30, 2010

Community Assist Use Cases

Here are some use cases that describe how the various actors will use the
community Assist application


Excercise 1 chapter 3 and arrays

Here is the code we did in class


#include
using namespace std;

void ConvertInches(int inches);

int main()
{
cout << "Please Enter your height in inches." << endl;
int inch;
cin << inch;
ConvertInches(inch);

char c;
cin << c;
}

void ConvertInches(int inches)
{
const int FOOT=12;
int heightInFeet = inches / FOOT;
int remainingInches = inches % FOOT;

cout << "you are " << heightInFeet << " feet and "
<< remainingInches << " inches tall." << endl;

}

Here is the code for the arrays

#include
#include //add the string library
using namespace std;

int main()
{
const int size =5; //declare a constant

int myArrayb[size]; //arrays require a constant for limit

int myArray[4] = {4,7,23,16}; //initialize the array

char name[]="George Jetson";//character array


//this gets the character array and the length of
//the character array and then choses the fifth character
//from the array
cout << "Your name is "<< name << "there are "
<< strlen(name) << " characters in your name"
<< "The fifth character is " << name[4] <<
endl;

//gets the third element from the first array
cout << "the 3rd element is " << myArray[2] << endl;

//use of getline with a character array
cout << "enter your first and last name" << endl;
char fullName[25];
cin.getline(fullName, 25);

string address; //declare a variable as string
cout << "Enter your address" << endl;
//use string getline
getline(cin, address);

cout << "Your name is " << fullName << endl;
cout << "Your address is " << address << endl;

//just pause the program waiting for a character
//to be entered
char c;
cin << c;


}

Monday, June 28, 2010

First C++

Here is the first C++ code example:



#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int cube(int); //function prototype

int main()
{
/* this is a simple hello application
the comment can cross
several lines */
cout << "Enter your name" << endl;
char name[25];
cin.getline(name, 25);

cout << "Hello," << name << endl;

cout << "Enter a number" << endl;
int num;
cin >> num;
cout << "the cube of " << num << " is " << cube(num) << endl;
cout << "The square root of " << num << " is " << sqrt((double)num) << endl;
//this is just to pause the console
char c; //declare a character type variable
cin >> c; //wait for console entry
}

int cube (int x)
{
return x * x * x;
}

Tuesday, June 1, 2010

Misc Object Oriented concepts

An enumeration allows you to name a series of items only once and then use them everywhere. Here is the code for an enumeration of days of the week

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public enum DaysOfWeek
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
}

A structure allows you to create a complex type. Again it is a way of keeping you from having to rewrite the same information over and over. Here is a stucture for addresses.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public struct Address
{
string address1;
string address2;
string city;
string state;
string zipcode;


}
}

An interface is sometimes referred to as a contract. An interface consists only of method signatures. any class that implements an interface MUST implement all its methods. Here is the interface:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public interface iManage
{
void Add(object s);

void Edit(object s);

void Remove(object s);
}
}

Here is a clsss that implements the IManage interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
class ManageScan:iManage
{
#region iManage Members

void iManage.Add(object s)
{
throw new NotImplementedException();
}

void iManage.Edit(object s)
{
throw new NotImplementedException();
}

void iManage.Remove(object s)
{
throw new NotImplementedException();
}

#endregion
}
}

Finally, here is an Abstract Class. It is a sort of a combination of an interface and a structure. It cannot be instantiated in itself. Only its children can be instantiated. Here is an abstract class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public abstract class Class1
{
private int FirstName;

public int FirstName1
{
get { return FirstName; }
set { FirstName = value; }
}
private int LastName;

public int LastName1
{
get { return LastName; }
set { LastName = value; }
}

public virtual void GetPersonInfo()
{

}
}
}

I will do a program soon that uses all these elements to provide a working example