HOME

CS 2511

CS 3810

CS 4600

CS 5610

CS 2511
STUDENT WEBPAGES
CS 2511
ASSIGNMENTS
CS 2511
TEST REVIEW
CS 2511
CLASS NOTES

CLASS NOTES FOR CS 2511

9/10/02 | 9/17/02| 9/19/02| 9/26/02| 10/22/02| 11/12/02|

CLASS NOTES FOR 9/10/02


Delimiter = pauses

 

Why lowercase is different then Uppercase?

·                They have different code.

·                They have different character.

·                A programmer didn’t program it.

 

ASCII (ASKEY) = Numeric Code

·                A = 65

·                B = 66

·                C = 67

·                D = 68

·                Z = 90

 

Lowercase a is?

97

 

 

How can you solve uppercase, lowercase problem?

Convert it (program it to change cases)

 

Way to solve a problem is = Algorithm

SEARCH (User needs to create a data.in file)

#include <fstream.h>
#include <string.h>

main(){
 char searchname [15], name [15], telephone [14];
 cout << " enter the serch name:";
 cin>> searchname;
 ifstream fin ("data.in");
  while (fin>>name>>telephone){
   if (strcmp(searchname,name)==0){
    cout<<telephone<<endl;
   return  0;
  }//end of if
}//end of loop
cout <<"name not found"<< endl;
return 0;
}//end of main

BACK TO THE MAIN MENU....






CLASS NOTES FOR 9/17/02

Function and String is used for the following code!!

#include <fstream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>

myappend(char personname[],char phone[]){
 ofstream fout("directory.in",ios::app);
 cout<<"ENTER PERSON NAME ";
 cin>> personname;
 cout<<"ENTER THE PHONE ";
 cin>>phone;
 fout<<personname<<setw(20)<<phone<<endl;
 return 0; }//MY APPEND
mysearch(char personname[],char phone[]){
 char searchname[20];
 ifstream fin("directory.in",ios::in);
 cout<<"ENTER THE SEARCH NAME ";
 cin>>searchname;
 while(fin>>personname>>phone){
  if(strcmp(searchname,personname)==0){
  cout<<"THE PHONE IS "<<phone << endl << endl;
  return 1; }//IF
}//while

cout<<"NAME NOT FOUND" <<endl;
return 0; }//MYSEARCH
mydisplay(char personname[],char phone[]){
 ifstream fin("directory.in");
 while(fin>>personname>>phone){
  cout<<"PHONE IS  "<<phone<<endl; }//while
 return 0; } //mydisplay
main(){
 char option;
 char personname[20],phone[20];
 cout<<"SELECT ONE OF THE FOLLOWING"<<endl;
 while(1){
  cout<<"TYPE 1 TO INSERT "<<endl;
   cout<<"type 2 to display "<<endl;
   cout<<"type 3 to search " << endl;
   cout<<"type # to quit "<<endl;
   cin>>option;
   if(option=='1') myappend(personname,phone);
   else if (option=='2') mydisplay(personname,phone);
   else if (option=='3') mysearch (personname,phone);
   else if(option=='#') {cout<<"BYE"<<endl;exit(1);}
 }//while
 return 0;
}//main
BACK TO THE MAIN MENU....







CLASS NOTES FOR 9/19/02

. Searching is a concept
·Programs is made of Constructs

1.      Q) What are the constructs (languages)?
A) Words building the program (For loop, While loop)

 

·Data file? Silent (like fuel in the car). Program?
User types and it interacts with the datafile (like the engine in a car).


BACK TO THE MAIN MENU....






CLASS NOTES FOR 9/26/02

Payroll Program with the use of Arrays #include iostream.h

#include iomanip.h

main(){

char empid[100][12];

char fname[100][14], lastname[100][15];

int hw [100];

double gp [ 100 ], np [100] ,hr [100], taxrate [100], taxamt [100];

int counter = 0;

int i;

cout<<"ENTER EMP ID, FNAME, LANAME, HRS WORKED, HRLY RATE CTRL Z TO END"<<endl;

while(cin>>empid[counter]>>fname[counter]>>lastname[counter]>>hw[counter]>>hr[counter])

counter = counter + 1;

for (i = 0; i<counter; i++){

gp[i] = hw [i]* hr[i];}//end grosspay for loop

for (i=0; i<counter;i++){

if (gp[i]>500) taxrate[i] = .30;

else if (gp[i]>200) taxrate[i]=.20;

else taxrate [i] = .10;

}

//for

for (i= 0; i < counter; i++){

taxamt[i] = gp [i]* taxrate [i];}//end taxamount for loop

for ( i = 0; i<counter; i++){

np[i] = gp [i] - taxamt [i]; } //end netpay for loop

cout << endl;

cout << setw(14)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)

<<"LAST NAME" <<setw(4)<<"HW"<<setw(5)<<"HR"<<setw(6)

<<"GROSS"<<setw(6)<<"TAX"<<setw(9)<<"NET PAY"<< endl<<endl;

for (i=0;i<counter; i++){

cout<<setw(14)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)

<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]<<setw(6)<<taxamt[i]<<setw(9)<<np[i]<<endl;

}//for

return 0;

} //Main

BACK TO THE MAIN MENU....






CLASS NOTES FOR 10/22/02

Convert Simple Database with Menu using Arrays to take Advantage

 

#include <fstream.h>

#include<iomanip.h>

#include<string.h>

#include<stdlib.h>

int counter = 0;

char personname[20][20], phone[20][20];

 myappend(char personname[][20],char phone[][20],int &counter){

 cout<<"ENTER PERSON NAME ";

 cin>> personname[counter];

 cout<<"ENTER THE PHONE ";

 cin>>phone[counter];

 counter++;

 cout<<"COUNTER IS "<<counter<<endl;

 return 0; }//MY APPEND

mysearch(char personname[][20],char phone[][20], int &counter){

 char searchname[20];

 cout<<"ENTER THE SEARCH NAME ";

 cin>>searchname;

 for(int i = 0; i<counter;i++){

  if(strcmp(searchname,personname[i])==0){

  cout<<"THE PHONE IS "<<phone[i] << endl << endl;

  cout<<"COUNTER IS "<<counter<<endl;

 

  return 1; }//IF

}//wfor

cout<<"NAME NOT FOUND" <<endl;

return 0; }//MYSEARCH

 

mydisplay(char personname[][20],char phone[][20],int &counter){

 for(int i= 0; i<counter;i++){

  cout<<"Person Name Is "<< personname[i]<<endl;

  cout<<"PHONE IS  "<<phone[i]<<endl; }//while

 return 0; } //mydisplay

main(){

 char option;

 char personname[20][20],phone[20][20];

 cout<<"SELECT ONE OF THE FOLLOWING"<<endl;

 while(1){

  cout<<"TYPE 1 TO INSERT "<<endl;

   cout<<"type 2 to display "<<endl;

   cout<<"type 3 to search " << endl;

   cout<<"type # to quit "<<endl;

   cin>>option;

   if(option=='1') myappend(personname,phone, counter);

   else if (option=='2') mydisplay(personname,phone,counter);

   else if (option=='3') mysearch (personname,phone,counter);

   else if(option=='#') {cout<<"BYE"<<endl;exit(1);}

 }//while

 return 0;

}//main

BACK TO THE MAIN MENU....






CLASS NOTES FOR 11/12/02

BACK TO THE MAIN MENU....







(This is the end of the page.)

1