coe116 sample codes - / pointers_ex1.cpp : Defines the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// pointers_ex1.cpp : Defines the entry point for the console application. //this application will convert GN MN SN into SN, GN MI. //pointers_ex3.cpp #include "stdafx.h" #include <iostream> #include "pointers_ex1.h" #include <conio.h> #include <string> using namespace std; int _tmain( int argc, _TCHAR* argv[]) { char *p; string str; int x=0, y=0; p = new char [100]; cout<< "Enter name:" ; gets(p); pointers_ex1 ex1(p); p = ex1.merge(); while (p[y]!= '.' ) { y++; } y++; while (x!=y) { cout<<p[x]; x++; } getch(); return 0; } //pointers_ex1.h #pragma once class pointers_ex1 { public : pointers_ex1( char *); ~pointers_ex1( void ); char * merge(); private : char *fname,*mi,*sname,*name; int a,b,c; }; pointers_ex1::pointers_ex1( char *str) { fname = new char [100]; mi = new char [10]; sname = new char [100]; int x=0, y=0; while (str[x]!= ' ' ) { fname[x]=str[x]; x++; } a=x; x++; mi[0] = toupper(str[x]); while (str[x]!= ' ' ) x++; while (str[x]!= NULL) { sname[y] = str[x+1]; y++; x++; } b=y; } pointers_ex1::~pointers_ex1( void ) { } char * pointers_ex1::merge() { name = new char [100]; int x=0, y=0; while (x!=b) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
name[x] = sname[x]; x++; } name[x] = ',' ; x++; name[x] = ' ' ; x++; while (y!=a) { name[x] = fname[y]; x++; y++; } name[x] = ' ' ; x++; name[x] = mi[0]; x++; name[x] = '.' ; return name; } //pointers_ex2.cpp #include <iostream> #include <conio.h> #include <math.h> #include "pointers_ex2.h" using namespace std; struct Date { int month; int day; int year; }; class pointers_ex2 { public : pointers_ex2( void ); ~pointers_ex2( void ); void assign1(Date*); void assign2(Date*); int compute(); private : int x,y; }; void pointers_ex2::assign1(Date* date) { x=(date->year*360) + (date->month*30) + (date->day);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2011 for the course COM 285 taught by Professor Randiplante during the Spring '10 term at University of the Philippines Los Baños.

Page1 / 8

coe116 sample codes - / pointers_ex1.cpp : Defines the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online