Git Product home page Git Product logo

string_functions's Introduction

string_functions

Assignment 2 from Intro programming class 1

Emily Zastenchik Assignment 2

Problem:

Return original string of 4 words spaced with "" in reverse order without spaces using function prototype: string split_and_reverse(string) (function must: -extract each word from original string and store each token as a string object -concatenate words in reverse order as a string -return result as a string Example. Theskyisblue (original string) blueusskythe (final string)

Analysis:

INPUTS 

 string fullName				//fullName = firstName+lastName
	 gender
 
OUTPUTS 

    string fullName		//original string "Hello*Mr./Ms.*fullName
    string R = split_and_reverse(s)		//final string "lastNamefirstNameMr./Ms.hello"
    
FUNCTIONS 

	string split_and_reverse(string)
  
		member functions -
			getline
			astring.assign
			astring.replace
			astring.erase

Design:

Ask user for first name and last name

Use getline function to store both tokens in fullName

Use replace function to replace " " with "*" in fullName 

Ask for gender

	Pass gender through if statement
  
	Display original function
  
Pass original function through split_and_reverse function

	string h, m, f, l, R
	h.assign(a, 0, a.find("*"))				//h = Hello
	h.replace(0, 1, "h")					//h = hello
	m.assign(a, a.find("*") + 1, 3)			//m = (Ms./Mr.)
	a.erase(0, h.length() + m.length() + 2)	//a = fullName
	f.assign(a, 0, a.find("*"))				//f = firstName
	a.erase(0, f.length() + 1)				//a = lastName
	l.assign(a, 0, a.length())				//b = lastName
	R = l + f + m + h						//R = lastNamefirstName(Ms./Mr.)hello
Return final string R

string_functions's People

Contributors

emilyzastenchik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.