Forum Replies Created
- AuthorPosts
- GWILouisaxwzklaParticipant
try:
12345678<br /><br />#include <br />void main()<br />{<br />printf("nHello Worldn");<br />}<br />GWILouisaxwzklaParticipantIs the code to be in c or c++? If in C++ you could easily type the proper combinations of input ( for the first line for example ):
123456<br />inputFile >> word; //get "Training"<br />inputFile >> word;//get "File"<br />inputFile >> word// get "="<br />inputFile.getline ( fileString , MAX_LENGTH , 'n' ); //get ".ts_ce_D_0.5-1.5_train3.sdf"<br />simple but tedious ………
GWILouisaxwzklaParticipantThe average is calculated in the line:
123<br />printf ( "The miles/gallon for this tank was : %f n" , miles / gallons );<br />the compiler sets up a hidden temporary variable to hold the result of ( miles/gallons ) and then sends this result to the printf () function to print it……..
GWILouisaxwzklaParticipantIf your in the main function you could just use a return statement , I’d have to see the code , though…
December 16, 2008 at 8:10 pm in reply to: C program that computes the value of ex using a formula #3501GWILouisaxwzklaParticipanttry:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,15,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 3:08:27 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream ><br />//#include < string.h ><br />//#include < conio.h ><br />#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br />using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int terms;<br />double powerOfX;<br />double e = 1;<br />double i = 1;<br />double j ;<br />double k = 2;<br /><br />printf ( "Enter value of x : " );<br />scanf ( "%lf" , & powerOfX );<br />printf ( "Enter the number of terms ( greater or equal to one ) : " );<br />scanf ( "%i" , & terms );<br />j = powerOfX;<br /><br /><br /><br />while ( terms > 1 )<br />{<br />e = e + ( j * ( 1 / i ) );<br />terms --;<br />i = i * k;<br />j = j * powerOfX;<br />k ++;<br /><br />}<br />printf ( "The approximated value of ex : %.12lf n" , e );<br />printf ( "The value of ex using C library function %.12lf: n" ,exp( powerOfX ) );<br />printf ( "The absolute difference between the two value : " );<br />printf ( "%.12lf n" , fabs ( exp ( powerOfX ) - e ) );<br />return 0 ;<br />}<br />I didn’t know how many digit to output so I chose 12 like the example. You can change this by changing the number listed after the ‘.’ in the last printf() statements.
Theres an error in the code I posted for the approximation of e = 1 + 1/1! + 1/2! . Heres the proper code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758<br /><br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,15,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 3:08:27 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream ><br />//#include < string.h ><br />//#include < conio.h ><br />#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br />using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int terms;<br />double powerOfX;<br />double e = 1;<br />double i = 1;<br />double j ;<br />double k = 2;<br /><br /><br />printf ( "Enter the number of terms ( greater or equal to one ) : " );<br />scanf ( "%i" , & terms );<br /><br />while ( terms > 1 )<br />{<br />e = e + ( 1 / i ) ;<br />terms --;<br />i = i * k;<br />k ++;<br /><br />}<br />printf ( "The approximated value of e : %.12lf n" , e );<br />printf ( "The given mathematical constant e = 2.718281828459 n");<br />printf ( "The absolute difference between the two value : " );<br />printf ( "%.12lf n" , fabs ( 2.718281828459 - e ) );<br /><br />return 0 ;<br />}<br />December 15, 2008 at 8:34 pm in reply to: C program that estimates the value of the math constant e #3500GWILouisaxwzklaParticipantcout and cin are input and output members of a stream object in the file iostream.h . This header file is associated with c++ programs and the method that most c++ programmers use for input and output. cout stands for “console output” and cin stands for console input. You can use them more easily than printf and scanf :
12345678910<br /><br />int i = 1;<br />char c = 'd';<br />.....<br /><br />cout << "the int is: " << i << endl; //output : the int is: 1<br />cout << "the char is" << c << endl; // output : the char is d<br /><br />for the program , try:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960<br /><br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,15,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 3:08:27 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />//#include <br />//#include <br />#include <br />//#include <br />//#include <br /><br />using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int terms;<br />double powerOfX;<br />double e = 1;<br />double i = 1;<br />double j ;<br />double k = 2;<br /><br /><br />printf ( "Enter the number of terms ( greater or equal to one ) : " );<br />scanf ( "%i" , & terms );<br /><br />while ( terms > 1 )<br />{<br />e = e + ( 1 / i ) ;<br />terms --;<br />i = i * k;<br />k ++;<br /><br />}<br />printf ( "The approximated value of e : %.12lf n" , e );<br />printf ( "The given mathematical constant e = 2.718281828459 n");<br />printf ( "The absolute difference between the two value : " );<br />printf ( "%.12lf n" , fabs ( 2.718281828459 - e ) );<br />return 0 ;<br />}<br /><br /><br /><br />GWILouisaxwzklaParticipantThe structs will form a linked list , correct? The sorting key will be variable amongst the struct field members ( the user will chose a struct member to sort the data on ) ?? Is the list to be “disconnected” for sorting ( structs will be moved and the list reconnected ) or is data to be shifted ( probably easier )…
GWILouisaxwzklaParticipantCould do:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,15,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:39:00 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br />//using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />float gallons , miles;<br /><br />printf ( "Enter the gallons used (-1 to end) : " );<br />scanf ( "%f" , & gallons );<br />while ( gallons != -1 )<br />{<br />printf ( "Enter the miles driven : " );<br />scanf ( "%f" , & miles );<br />printf ( "The miles/gallon for this tank was : %f n" , miles / gallons );<br />printf ( "Enter the gallons used (-1 to end) : " );<br />scanf ( "%f" , & gallons );<br />}<br />return 0 ;<br />}<br /><br /><br /><br />GWILouisaxwzklaParticipantcould do:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,7,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:59:36 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />//#include <br />//#include <br />//#include <br />//#include <br />//#include <br /><br />//using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />char choice;<br />int number1 , number2 , number3 , number4,number5;<br />int average;<br />do<br />{<br />printf ( "enter a number: " );<br />scanf ( "%i" , & number1 );<br />printf ( "enter a number: " );<br />scanf ( "%i" , & number2 );<br />printf ( "enter a number: " );<br />scanf ( "%i" , & number3 );<br />printf ( "enter a number: " );<br />scanf ( "%i" , & number4 );<br />printf ( "enter a number: " );<br />scanf ( "%i" , & number5 );<br />printf ( "nthe average of the numbers is: " );<br />average = ( number1 + number2 + number3 + number4 + number5 ) / 5;<br />getchar (); //get new line characters<br />printf ( "%i" , average );<br />printf ( " nDo you want to calculate another average ? ( y or n ) " );<br />scanf ( "%c" , & choice );<br />getchar(); //get newline<br />while ( choice != 'y' && choice != 'n' )<br />{<br />printf ( "wrong input ( enter y or n ) " );<br />printf ( " nDo you want to calculate another average ? ( y or n ) " );<br />scanf ( "%c" , & choice );<br />getchar (); //get newline<br />}<br />}while ( choice != 'n' );<br /><br /><br />return 0 ;<br />}<br /><br /><br /><br /><br /><br />GWILouisaxwzklaParticipantcould do:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,7,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:47:31 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />//#include <br />//#include <br />//#include <br />//#include <br />//#include <br /><br />//using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int number;<br />int factorial = 1;<br />int i = 1;<br /><br />printf ( "Enter a positive integer : " );<br />scanf ( "%i" , & number );<br /><br /><br /><br />while ( i <= number )<br />{<br />factorial = i * factorial;<br />i ++;<br />}<br /><br />printf ( "the factorial is %i " , factorial );<br /><br />return 0 ;<br />}<br /><br /><br /><br /><br />GWILouisaxwzklaParticipantcould do
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,7,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:39:41 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int number;<br /><br />printf ( "enter a number: " );<br />scanf ( "%i" , & number );<br /><br />if ( number % 2 == 0 )<br />printf ( "The number is even n " );<br />else<br />printf ( "Then number is odd n " );<br /><br /><br />return 0 ;<br />}<br /><br /><br /><br />GWILouisaxwzklaParticipantNot sure exactly what you need , but here is something similar with an array of structs and a library inventory:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418<br />/****************************************************************<br />* File Name : c:programshelpshell.cpp<br />* Date : May,14,2007<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 1:40:06 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />#include <br />//#include <br />//#include <br />//#include <br />//#include <br /><br />using namespace std;<br /><br />struct PERSON<br />{<br /><br />string firstName;<br />string lastName;<br />string address;<br />string phoneNumber;<br />};<br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br />void addPerson ( PERSON & thisPerson );<br />void getPerson ( PERSON & thisPerson );<br />bool findPerson ( string & firstName );<br />bool findPerson ( string & firstName , string & lastName );<br /><br />void printBook ( void );<br />bool checkDuplicate ( PERSON & personToCheck );<br />bool insertAfter ( PERSON & personToAdd , int index );<br /><br /><br />//##################################################################################<br /><br /><br />//>>>>>>>>>>>>>>>>>>>>>>>> GLOBAL DATA <<<<<<<<<<<<<<<<<<<<<<<<<<br />const int MAX_PEOPLE = 3;<br />PERSON addressBook [ MAX_PEOPLE ] ;<br />int arrayIndex;<br />int itemsInAddressBook = 0;<br />//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />arrayIndex = 0;<br />PERSON temp;<br />char choice;<br />string firstName , lastName;<br /><br />do<br />{<br />cout << endl;<br />cout << "menu ***********" << endl;<br />cout << "1. add person" << endl;<br />cout << "2. get person " << endl;<br />cout << "3. find person ( full name ) " << endl;<br />cout << "4. find person ( first name ) " << endl;<br />cout << "5. print address book " << endl;<br />cout << "6. insert after another item " << endl;<br />cout << "7. quit" << endl;<br /><br />cout << endl << "enter choice ";<br /><br /><br />cin >> choice;<br />while ( choice != '1' && choice != '2' && choice != '3' && choice != '4' && choice != '5'<br />&& choice != '6' && choice != '7' )<br />{<br />cout << "Bad choice ( 1,2,3,4,5,6,7 ) , enter choice : ";<br />cin >> choice;<br />}<br />switch ( choice )<br />{<br />case '1':<br />{<br />cout << endl;<br />cout << "enter first name: ";<br />cin >> temp.firstName;<br />cout << "enter last name: ";<br />cin >> temp.lastName;<br />cout << "enter address ( $ to end input ): ";<br />cin.get();<br />getline ( cin , temp.address , '$' );<br />cout << "enter phone number: ";<br />cin >> temp.phoneNumber;<br />addPerson ( temp );<br />};<br />break;<br />case '2':<br />{<br />getPerson ( temp );<br />cout << endl;<br />cout << "name retrieved :";<br />cout << "first name : " << temp.firstName << endl;<br />cout << "last name : " << temp.lastName << endl;<br />cout << "address : " << temp.address << endl;<br />cout << "phone number : " << temp.phoneNumber << endl;<br />};<br />break;<br />case '4':<br />{<br />cout << "enter first name: ";<br />cin >> firstName;<br />if ( findPerson ( firstName ) )<br />cout << "name is in the address book " << endl;<br />else<br />cout << "name is not in the address book " << endl;<br />};<br />break;<br />case '3':<br />{<br />cout << "enter first name: ";<br />cin >> firstName;<br />cout << "enter last name: ";<br />cin >> lastName;<br /><br /><br />if ( findPerson ( firstName , lastName ) )<br />cout << "name is in the address book " << endl;<br />else<br />cout << "name is not in the address book " << endl;<br />};<br />break;<br />case '5':<br />{<br />printBook ( );<br />};<br />break;<br />case '6':<br />{<br />cout << "enter first name: ";<br />cin >> temp.firstName;<br />cout << "enter last name: ";<br />cin >> temp.lastName;<br />cout << "enter index to enter after : ";<br />int index;<br />cin >> index;<br />insertAfter ( temp , index );<br />};<br />break;<br />};<br />}<br />while ( choice != '7' );<br /><br /><br /><br /><br />return 0 ;<br />}<br /><br /><br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : addPerson<br />Parameters :<br /><br />thisPerson a(n) PERSON & ( PERSON & )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void addPerson ( PERSON & thisPerson )<br />{<br /><br /><br /><br />if ( arrayIndex >= MAX_PEOPLE )<br />arrayIndex = 0;<br /><br />if ( itemsInAddressBook < MAX_PEOPLE )<br />itemsInAddressBook ++;<br /><br />if ( checkDuplicate ( thisPerson ) == true )<br />{<br />cout << endl << "item already in data base ! " << endl;<br />return;<br />}<br /><br /><br />addressBook [ arrayIndex ].firstName = thisPerson.firstName;<br />addressBook [ arrayIndex ].lastName = thisPerson.lastName;<br />addressBook [ arrayIndex ].address = thisPerson.address;<br />addressBook [ arrayIndex ].phoneNumber = thisPerson.phoneNumber;<br /><br />arrayIndex ++;<br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : getPerson<br />Parameters :<br /><br />thisPerson a(n) PERSON & ( PERSON & )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void getPerson ( PERSON & thisPerson )<br />{<br /><br /><br /><br />if ( itemsInAddressBook == 0 )<br />{<br />cout << "adress book empty" << endl;<br />return;<br />}<br /><br />if ( arrayIndex >= MAX_PEOPLE )<br />arrayIndex = 0;<br /><br /><br />thisPerson.firstName = addressBook [ arrayIndex ].firstName;<br />thisPerson.lastName = addressBook [ arrayIndex ].lastName ;<br />thisPerson.address = addressBook [ arrayIndex ].address;<br />thisPerson.phoneNumber = addressBook [ arrayIndex ].phoneNumber;<br />arrayIndex ++;<br />if ( arrayIndex >= MAX_PEOPLE )<br />arrayIndex = 0;<br />if ( itemsInAddressBook < MAX_PEOPLE )<br />itemsInAddressBook ++;<br /><br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : findPerson<br />Parameters :<br /><br />firstName a(n) string & ( string & )<br /><br /><br />Returns: user defined type , bool<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool findPerson ( string & firstName )<br />{<br />int i = 0;<br /><br />while ( i < itemsInAddressBook )<br />{<br />if ( firstName == addressBook [ i ].firstName )<br />return true;<br />i ++;<br />}<br />return false;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : findPerson<br />Parameters :<br /><br />firstName a(n) string & ( string & ) ,<br />lastName a(n) string & ( string & )<br /><br /><br />Returns: user defined type , bool<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool findPerson ( string & firstName , string & lastName )<br />{<br /><br />int i = 0;<br /><br />while ( i < itemsInAddressBook && i < MAX_PEOPLE )<br />{<br />if ( firstName == addressBook [ i ].firstName && lastName == addressBook [ i ].lastName )<br />return true;<br />i ++;<br />}<br />return false;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : printBook<br />Parameters :<br /><br />void ( void )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void printBook ( void )<br />{<br />int i = 0;<br />while ( i < itemsInAddressBook && i < MAX_PEOPLE )<br />{<br />cout << i << ". " << addressBook [ i ].firstName<br /><< " " << addressBook [ i ].lastName<br /><< " " << addressBook [ i ].address<br /><< " " << addressBook [ i ]. phoneNumber << endl;<br />i ++;<br />}<br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : checkDuplicate<br />Parameters :<br /><br />personToCheck a(n) person & ( person & )<br /><br /><br />Returns: user defined type , bool<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool checkDuplicate ( PERSON & personToCheck )<br />{<br /><br />int i = 0;<br />while ( i < itemsInAddressBook && i < MAX_PEOPLE )<br />{<br />if ( personToCheck.firstName == addressBook [ i ].firstName<br />&& personToCheck.lastName == addressBook [ i ].lastName )<br />return true;<br />i ++;<br />}<br /><br /><br />return false;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : insertAfter<br />Parameters :<br /><br />personToAdd a(n) person & ( person & ) ,<br />index a(n) int ( int )<br /><br /><br />Returns: user defined type , bool<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool insertAfter ( PERSON & personToAdd , int index )<br />{<br /><br /><br />if ( checkDuplicate ( personToAdd ) == true )<br />{<br />cout << endl << "item already in data base ! " << endl;<br />return false;<br />}<br />if ( index > itemsInAddressBook )<br />{<br /><br />addressBook [ arrayIndex ].firstName = personToAdd.firstName;<br />addressBook [ arrayIndex ].lastName = personToAdd.lastName;<br />addressBook [ arrayIndex ].address = personToAdd.address;<br />addressBook [ arrayIndex ].phoneNumber = personToAdd.phoneNumber;<br />arrayIndex ++;<br />if ( arrayIndex >= MAX_PEOPLE )<br />arrayIndex = 0;<br />if ( itemsInAddressBook > MAX_PEOPLE )<br />itemsInAddressBook ++;<br />}<br />else if ( index < itemsInAddressBook )<br />{<br /><br />addressBook [ index + 1 ].firstName = personToAdd.firstName;<br />addressBook [ index + 1 ].lastName = personToAdd.lastName;<br />addressBook [ index + 1 ].address = personToAdd.address;<br />addressBook [ index + 1 ].phoneNumber = personToAdd.phoneNumber;<br /><br />if ( itemsInAddressBook <= MAX_PEOPLE )<br />itemsInAddressBook ++;<br /><br />}<br />return true;<br />}<br /><br /><br />GWILouisaxwzklaParticipantCould do this:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576<br />/****************************************************************<br />* File Name : c:programstempcg.cpp<br />* Date : December,1,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:09:49 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />//#include <br />//#include <br />//#include <br />//#include <br />//#include <br /><br />using namespace std;<br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />cout << "Enter change amount : ";<br />float change;<br />cin >> change;<br /><br />int hundreds = 0;<br />int fifties = 0;<br />int tens = 0;<br />int tempChange = change;<br /><br />while ( tempChange >= 100 )<br />{<br />hundreds ++;<br />tempChange -= 100;<br />}<br /><br />tempChange = change;<br />while ( tempChange >= 50 )<br />{<br />fifties ++;<br />tempChange -= 50;<br />}<br /><br />tempChange = change;<br />while ( tempChange >= 10 )<br />{<br />tens ++;<br />tempChange -= 10;<br />}<br /><br />cout << "you can change " << change << " with: " << endl;<br />cout << hundreds << " hundreds" << endl;<br />cout << fifties << " fifties " << endl;<br />cout << tens << " tens" << endl;<br /><br /><br />return 0 ;<br />}<br /><br />output:
123456789<br />Enter change amount : 200<br />you can change 200 with:<br />2 hundreds<br />4 fifties<br />20 tens<br />Press any key to continue<br /><br />GWILouisaxwzklaParticipantNot quite sure what you needed so I wrote this to read words from the keyboard into a character array. I haven’t tested this code much and the logic could probably be simplified….
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102<br /><br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />#include < ctype.h ><br />#define MAX_LENGTH 50<br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />char inputStr [ MAX_LENGTH ];<br />int i = 0;<br />cout << "Enter a string: " ;<br />cin.getline ( inputStr , MAX_LENGTH );<br />if ( inputStr [ 0 ] == 0 )<br />return 0; //empty string<br /><br />cout << "output: " ;<br />while ( inputStr [ i ] != 0 )<br />{<br /><br />if ( inputStr [ i ] == 'y' && ( inputStr [ i + 1 ] == 0 || isspace ( inputStr [ i + 1 ] ) ) )<br />{<br />cout << "ies" ;<br />i ++;<br />}<br />else if ( inputStr [ i ] == 's' && ( inputStr [ i + 1 ] == 0 || isspace ( inputStr [ i + 1 ] ) ) )<br />{<br />cout << "ses" ;<br />i ++;<br />}<br />else if ( inputStr [ i ] == 's' && inputStr [ i + 1 ] == 'h' )<br />{<br />if ( inputStr [ i + 2 ] == 0 || isspace ( inputStr [ i + 2 ] ) )<br />{<br />cout << "shes" ;<br />i += 2;<br />}<br />else<br />cout << inputStr [ i ++ ];<br /><br />}<br />else if ( inputStr [ i ] == 'c' && inputStr [ i + 1 ] == 'h' )<br />{<br />if ( inputStr [ i + 2 ] == 0 || isspace ( inputStr [ i + 2 ] ) )<br />{<br />cout << "ches" ;<br />i += 2;<br />}<br />else<br />cout << inputStr [ i ++ ];<br /><br />}<br /><br />else if ( isalnum ( inputStr [ i ] ) && ( isspace ( inputStr [ i + 1 ] ) || inputStr [ i + 1 ] == 0 ) )<br />{<br />cout << inputStr [ i ] << "s ";<br />i ++;<br />}<br />else<br />cout << inputStr [ i ++ ];<br /><br /><br />}<br />cout << endl;<br /><br />return 0;<br /><br />}<br /><br /><br /><br /><br />output:
12345<br />Enter a string: church mickey sucks<br />output: churches mickeies suckses<br />Press any key to continue<br />GWILouisaxwzklaParticipant4.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061<br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br />#define MAX_LENGTH 50<br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />FILE * file1 = fopen ( "c:\programs\data.txt", "r+" );<br />FILE * file2 = fopen ( "c:\programs\data2.txt", "w+" );<br />char word [ MAX_LENGTH ];<br /><br />if( file1 == 0 || file2 == 0 )<br />{<br />printf( "A file did not open n" );<br />return 1;<br />}<br /><br />fscanf ( file1 , "%s", & word );<br />while ( ! feof ( file1 ) )<br />{<br /><br />fprintf( file2 , word );<br />fprintf( file2 , "n" );<br />fscanf ( file1 , "%s", & word );<br />}<br />fclose ( file1 );<br />fclose ( file2 );<br />return 0;<br /><br />}<br />5.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263<br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br />#define MAX_LENGTH 50<br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int one , two , three , smallest;<br /><br />printf ( "enter an integer: " );<br />scanf ( "%i" , & one );<br />printf ( "enter an integer: " );<br />scanf ( "%i" , & two );<br />printf ( "enter an integer: " );<br />scanf ( "%i" , & three );<br /><br />if ( one < two )<br />smallest = one;<br />else<br />smallest = two;<br />if ( three < smallest )<br />smallest = three;<br /><br />printf ( "the smallest is %i n" , smallest );<br /><br /><br />}<br /><br /><br /><br /><br /><br /> - AuthorPosts