{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

coe116 sample codes - pointers_ex1.cpp Defines the entry...

Info icon This 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) {
Image of page 1

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

View Full Document Right 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); } void pointers_ex2::assign2(Date* date) { y=(date->year*360) + (date->month*30) + (date->day); } int
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern