






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







OBJECTIVE: To demonstrate what I have learned about programming in C++. I will design two programs, Program 1 and Program 2. Program 1 will demonstrate Binary output for a decimal input. Program 2 will demonstrate six library functions that will manipulate a string of data. PROCEDURE: I will break this into several steps, each having their own section in this report. Step #1, will use pseudo code to lay out the flow of information and to outline my thought process. Step #2, will be the writing of the code in the standard format without the use of pointers. I will compile and verify that the code operates as needed before converting the code that which uses pointers. Step#3 ,is where I will convert the C++ code into a program that uses pointers. This is the same format that we use in the classroom. Step #4, will involve me placing this document and both “Final Exam Programs” on the ECET Web Site. PROGRAM 1. STEPS: #1 Pseudo code for program 1 “Bit-manipulation”: Get input from the user, cin>> decimal number between 0 & 255 Verify that the number is what is been requested by using a loop Output the value in binary. Output the data bit-by bit in a vertical format In the middle of this process my wife interrupted me to put up Christmas decorations!!
if (Dec >= P2) {Dec = Dec - P2; B2 = 1;}; if (Dec >= P1) {Dec = Dec - P1; B1 = 1;}; B0 = Dec; } else { cout << "Please Type a Decimal Number between 0-255: "; cin >> Dec; } //cout << "You entered " << Dec << endl; cout << ""<< endl; cout << "Bit 7 is " <<B7 << " MSB"<<endl; cout << ""<< endl; cout << "Bit 6 is " <<B6 << endl; cout << ""<< endl; cout << "Bit 5 is " <<B5 << endl; cout << ""<< endl; cout << "Bit 4 is " <<B4 << endl; cout << ""<< endl; cout << "Bit 3 is " <<B3 << endl; cout << ""<< endl; cout << "Bit 2 is " <<B2 << endl; cout << ""<< endl; cout << "Bit 1 is " <<B1 << endl; cout << ""<< endl; cout << "Bit 0 is " <<B0 << " LSB"<<endl; char c1; cin>>c1; }
Please Type a Decimal Number between 0-255: 128 Bit 7 is 1 MSB Bit 6 is 0 Bit 5 is 0 Bit 4 is 0 Bit 3 is 0 Bit 2 is 0 Bit 1 is 0 Bit 0 is 0 LSB Please Type a Decimal Number between 0-255: 999 Please Type a Decimal Number between 0-255: 64 Bit 7 is 0 MSB Bit 6 is 1 Bit 5 is 0 Bit 4 is 0 Bit 3 is 0 Bit 2 is 0 Bit 1 is 0 Bit 0 is 0 LSB
Ar[3] = 4; Ar[4] = 8; Ar[5] = 16; Ar[6] = 32; Ar[7] = 64; Ar[8] = 128; for (x=1; x <= 8; x++) {bit[x] =(p1 &Ar[x]) / Ar[x];} //Output to Screen in Binary cout<<""<<endl; cout <<"Bit 8 is " << bit[8]<< " MSB"<<endl; cout <<"Bit 7 is " << bit[7]<< endl; cout <<"Bit 6 is " << bit[6]<< endl; cout <<"Bit 5 is " << bit[5]<< endl; cout <<"Bit 4 is " << bit[4]<< endl; cout <<"Bit 3 is " << bit[3]<< endl; cout <<"Bit 2 is " << bit[2]<< endl; cout <<"Bit 1 is " << bit[1]<< " LSB"<<endl; } cout<<""<<endl; cout << "Please Input a Decimal Number Between 0-255:"; cin>>p1; } char c1; cin>>c1; } EXPECTED OUTPUT: Design By Jeff Kohn Please Type a Decimal Number between 0-255: 128 Bit 8 is 1 MSB Bit 7 is 0 Bit 6 is 0 Bit 5 is 0 Bit 4 is 0 Bit 3 is 0 Bit 2 is 0 Bit 1 is 0 LSB
Please Input a Decimal Number Between 0-255: Please Input a Decimal Number Between 0-255: Bit 8 is 0 MSB Bit 7 is 0 Bit 6 is 0 Bit 5 is 0 Bit 4 is 0 Bit 3 is 0 Bit 2 is 0 Bit 1 is 1 LSB Please Input a Decimal Number Between 0-255: PROGRAM 2. STEPS: #1 Pseudo code for program 2 “String -manipulation”: I decided to just write a variety of programs. STEP #2 C++ Program without pointers I decided to try just writing the program from scratch using pointer instead of converting them into pointers. STEP #3 C++ Program with pointers /* FINAL EXAM PART 2 This program will demonstrate string manipulation. I will be using pointers! Jeff Kohn ECET- December 9, */ #include
output(&number); calculate (total,x); invert_calculate(total,x); cout<<""<<endl; cout<<""<<endl; cout<<" *****************************************************"<<endl; cout<<" * JEFF DID A GOOD JOB IN C++ AND SHOULD GET AN A++ "<<endl; cout<<" *****************************************************"<<endl; char c1; cin>> c1; } void my_input (charp1) { cout<<"THIS PROGRAM TESTS A CHARACTER"<<endl; cout<< "Enter any character: "; cin>> p1; cout<< "The character you entered is: "<<p1<<endl; if (isalpha(p1)) cout<< "That is an alphebetic character.\n"; if (isdigit(p1)) cout<< "That is an numeric digit.\n"; if (islower(p1)) cout<< "That letter you entered is lowercase.\n"; if (isupper(p1)) cout<< "That letter you entered is uppercase.\n"; if (isspace(*p1)) cout<< "That is a white space character.\n"; } void my_lower (char p2) { cout<<""<<endl; cout<<""<<endl; cout<<"THIS WILL CONVERT THE CASE OF A SINGLE CHARACTER FROM UPPER TO LOWER."<<endl; cout<< "Enter a single character in UPPERCASE.:"; cin >>(p2);
cout<<(char)tolower(p2) << endl; } void my_upper (charp3) { cout<<""<<endl; cout<<""<<endl; cout<<"THIS WILL CONVERT THE CASE OF A SINGLE CHARACTER FROM LOWER TO UPPER."<<endl; cout<< "Enter a single character in lower case.:"; cin >>(p3); cout<<(char)toupper(p3) << endl; } /* This program uses the modulus operator to determine if a number is odd or even. If the number is evenly divisible by 2, it is an even number. A remainder indicates it is odd. I modified this to use pointers / void oddevenin(intp4) { cout<<""<<endl; cout<<""<<endl; cout<<"THIS WILL TELL YOU IF A NUMBER IS ODD OR EVEN."<<endl; cout << "Enter an integer and I will tell you if it\n"; cout << "is odd or even. "; cin >> p4; } void output(intp5) { if(*p5 % 2 == 0) cout << *p5 << " is even.\n"; else cout << *p5 << " is odd.\n"; } /////////////////////////////////////////////// ////////////////////////////////////////////// void calculate(int total, int x) { cout<<""<<endl; cout<<"THIS PROGRAM CALCULATES PERCENTAGE:"<<endl; float answer;