New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Introduction to Computer Science

by: Alek Haley

Introduction to Computer Science CS 1400

Marketplace > Utah State University > ComputerScienence > CS 1400 > Introduction to Computer Science
Alek Haley
Utah State University
GPA 3.58

Curtis Dyreson

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Curtis Dyreson
Class Notes
25 ?




Popular in Course

Popular in ComputerScienence

This 6 page Class Notes was uploaded by Alek Haley on Wednesday October 28, 2015. The Class Notes belongs to CS 1400 at Utah State University taught by Curtis Dyreson in Fall. Since its upload, it has received 12 views. For similar materials see /class/230444/cs-1400-utah-state-university in ComputerScienence at Utah State University.

Similar to CS 1400 at Utah State University

Popular in ComputerScienence


Reviews for Introduction to Computer Science


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/28/15
CS 1400 Chapter 10 101 Character Testing There are several functions that answer questions about characters Each has one char parameter Each returns true or false Character Testing require cctype header e 2 FUNCTlON MEANlNG lsalpha true if arg is a letter false OtherWlSe isalhum true irarg is a letter or digit false Otherwise isdigit true if arg is a digit 079 false Otherwise lslower true if arg is lowercase letter false OtherWlSe ispriht true if arg is a printable character false Otherwise ispuhct true if arg is a punctuation character false Otherwise isupper true if arg is an uppercase letter false OtherWlSe isspace true if arg is a Whitespace character false Otherwise Example cout ltlt Entel any charactel quot cih get input 1 cout ltlt The character you ehtereti 15 if lisalpha1nput hat if lsdlqlt1nput cout ltlt That39s a numeric d1qitnquot llnputl he letter you entered is lowercasen ltlt input ltlt endl ah aiphahetic character nputii hat39s a whitespace charactern 102 Character Case Conversion Require cctype header file Functions touppe return uppercase equivale unchanged f char argument is lowercase letter otherwise return input char chi 39H39 char ch2 e char c113 w char cl toupperch1 assigns 39H39 char c2 toupperch2 assigns 39E39 char c3 toupperch3 assigns w Character Case Conversion Functions tolower if char argument is uppercase letter return lowercase equivalent otherwise return input unchanged char c111 char c112 char c113 char cl toupperch1 char c2 toupperch2 char c3 toupperch3 assigns h39 assigns e assigns i 103 Review of the Internal Storage of CStrings Cstring sequence of characters stored in adjacent memory locations and terminated by NULL character Strin literal string constant sequence of characters enclosed in double quotes quot quot quotHi therequot IHlil ltlhlelrle l1 M Review of the Internal Storage of CStrings Array of chars can be used to define storage for string const int SIZE 20 char citySIZE Leave room for NULL at end Can enter a value using cin or gtgt Input is whitespaceterminated No check to see if enough space For input containing whitespace and to control amount of input use cin getline can write entire array using cout coutltltcity Review of the Internal Storage of CStrings Program 105 Thls progtam displays a Ecrlnq stored in a Char array ancmae lt1osueamgt usan namespace std 1n maln const int 51m an Array slze char 11neSIZEl To hold e llne of anut 111 count a Loop counts varlable Get a 1me of lupuc Dlsplay the 11 r one character at a tune entered 15n whlle lJlneco r cout ltlt 11necount Count l return a Program output wllh Example Input Shown In Bold 104 Library Functions for Working with CStrings These functions require cstrings as parameters actually the address of a cstring This can be accomplished by sending the name of an array holding a cstring a char pointer we39ll learn about these later a string constant Some of these cstring functions lead to potential security hazards and have been deprecated These will produce a warning in the Visual Studio environment Although the textbook uses the deprecated versions of these functions we will use the newer more secure versions Library Functions for Working with CStrings Functions strlenstr returns length of Cstring str char citySIZE quotMissoulaquot cout ltlt strlencity prints 8 strcats strl str2 appends str2 to the end of strl const int SIZE 100 char locationSIZE quotMissoula quot char state3 quotMTquot strcatslocation state location now has quotMissoula MTquot Library Functions for Working with CStrings Functions strcpys strl str2 copies str2 to strl const int SIZE 100 char fnameSIZE quotMaureenquot nameSIZE strcpysnamefname Cstring Inside a Cstring 10 The C String Class Function Cstring has some limitations strcmpstr1 str2 compares str1 with str2 You have to know how big to make it when Returns 0 if they are the same you declare it Returns a positive number if str1gt str2 You have to manage bounds Checking Returns a negative number if str1lt str2 I char mm Heno You have to use the available functions to char str2 hella perform common tasks 1f strclnpstrlstr2gt0 strcpys coutltltstrlltlt ls greater than ltltstr2ltltehdl else if strclnpstrlstr2 lt0 strcmp coutltltstrlltlt ls shorter than ltltstr2ltltehdl strlen coutltltstrlltlt ls the same as ltltstr2ltltehdl o strcat 5 else The C String Class Example 0 Special data type supports working with strings Program 1012 0 include ltstringgt Thls progl am demonstrates the 5mm class include ltlostlealugt 0 Can define strlng variables In programs klnclude emmp Requlred m the stung class using namespace std strlng flrstName lastName 0 Can receive values with assignment operator 3 in firstName quotGeorgequot string movieTitle lastName quotWashingtonquot i movieTitle e heels of r r cout IltDHy favcirlte movie 5 quot ltlt movie l ltle ltlt en ll cout ltlt firstName ltlt quot quot ltlt lastName Program Output My favol ite movie is Wheels of Fury The C String Class The C String Class Program iii n Use cin gtgt to read an item into a string string firstName cout ltlt quotEnter your first name quot in taint cin gtgt firstName string lane Input into a string Object Use getline function to put a line of input possibly including spaces into a string string address cout ltlt quotEnter your address quot getlinecinaddress string Comparison Can use relational operators directly to compare string objects string strl quotGeorgequot str2 quotGeorgiaquot if strl lt str2 cout ltlt strl ltlt quot is less than quot ltlt str2 Comparison is performed similar to strcmp function Result is true or false oltgt lt gt 22 Example Program 1015 Tms prsqrsm uses reisnensi vperaturs ta siphsbemesi y r tw errrngs entered by the user int main l String name nemez cout ltlt Enter s name llast nsme isrsri getlinElcin nemeii Get another nsme cout ltlt Enter another nsme H getlinelcin nameZl Display them n alphabetical srder cout ltlt Here sre the nsmes sorted alphabeticallyn nognm lle wllh Kample Inpm Shown In Boll Enter s meme last name fustl Smkhlllchardmu Enter another name lonex Iohu Inner Here sre the names sorted alphabetically anes Juhn smsrn Richard strings It also works with the operator The operator performs concatenation fullNamefirst quot quot last You can use the array operator to access a single a character titlequotlce Agequot coutltlttitle4prints A Other Definitions of C strings There are multiple ways to define a string Definition Meaning string name defines an empty string object string myname quotChrisquot defines a string and initializes it string defines a string and initializes it yourname myname string aname myname defines a string and initializes it with 3 first 3 characters of myname string defines a string and initializes it with 2 verb myname 3 2 characters from myname star ing at position 3 string noname A 5 defines string and initializes it to 5 A S string Operators OPERATOR MEANING gtgt extracts characters from stream up to whitespace insert into string ltlt inserts string into stream assigns string on right to string object on left appends string on right to end of contents on left concatenates two strings references character in string using array notation gt gt lt relational operators for string comparison Return true or lt false string Operators I Program 104 7 string wordl phrase string word2 quot Dogquot cin gtgt wordl user enters quotHot Tamalequot wordl has quotHotquot phrase wordl word2 phrase has 3 quotHot Dogquot t namespace std mt new i neime three smug objects 5t 9 stri em stri n values to en three phrase quot on a bunquot for int i O i lt 16 i cout ltlt phrase i displays m w and Why m quotHot Dog on a bunquot 9irmmm nagnm ompm AEC nap AECDEF AECDEFG a 1 string Member Functions string Member Functions Are behind many overloaded operators I Catego es string wordl word2 phrase 39 Cin gtgt wordl wordl is quotHotquot word2assignquot Dogquot phraseappendwordl as gnmemassign copy data modmca on appendclear erase insert replace swap t I phraseappendword2 phrase has quotHot Dogquot Space39 anagemen39C paClty39 empty phraseappendquot with mustard relishquot 13 length resize size phrase has quotHot Dog with mustardquot substrings find substr phraseinsert8 quoton a bun quot comparison compare cout ltlt phrase ltlt endl displays quotHot Dog on a bun with mustardquot See Table 107 for a list of functions Arrays of strings Program 1 Oil 8 This progl am demonstrates a string These are 1D arrays llquotSilii iiii lfmm string titlessize Flinclutle sstrmggt using namespace std int marn i string town com e quotwhere do you live 39 cin 239 town csut ltlt quotYour town39s name has ltlt townlengthl cout ltlt quot characters39ul return U l Pvtgram Output wlth Example Input Where do you live lacksollvllle Enter Inur town39s name has 12 characters Passing strings to Functions In the prototype void functionstring In the call functionmyString In the de nition void functionstring title Example string Name coutltlt Enter your name quot cingtgtName showStringName void showStringstring str coutltltstrltltend


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Amaris Trozzo George Washington University

"I made $350 in just two days after posting my first study guide."

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.