I have three c books on my desk right now, one under each side monitor to level them with the center and one under my laptop stand to level it with its second monitor.... I spent that class doodling in the back of the room.
I love reading this stuff because the cleverness being displayed makes me feel warm and fuzzy inside. It's the same feeling I get when I recite gun specifications to people.
No the bunny and children are safe...its your *** that is going to be burning in hell for your transgressions. Peter Norvig sits at the gates of heaven with a giant paddle just for that purpose
This is ugly as fuck because I'm snatching bits and pieces from all over the web. Code: // Homework 2.cpp : Defines the entry point for the console application. // #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } #include <iostream> #include <string> #include <sstream> #include <math.h> using namespace std; int main() { float size = 0; //size must be an integer, however the declaration of size as float allows the while loop below to filter out any user intput float number. This is better than the float being cast to an int by the program, because the user is made aware of their error, and a message will appear. string input = ""; //Create an Array of user input size cin.clear(); cout << "Enter Array Size" << endl; while(size <1 || size - floor(size) != 0 || !(cin.good())) // testing for Integer only input { cin.clear(); // clear error condition cin.ignore(100,'\n'); // remove characters cout << "Please enter an integer value greater than or equal to 1. Size = "; cin >> size; } //Create the array with the size the user input int *myArray = new int[size]; //Populate the array with user input for(int i = 0; i < size; ++i) { float num = 0.5; //num must be an integer, however the declaration of num as float allows the while loop below to filter out any user intput float number. This is better than the float being cast to an int by the program, because the user is made aware of their error, and a message will appear. bool unique = true; //Fill position i of the Array from user input cout << "\nEnter Integer: " << endl; while(num==0.5 || !(cin.good())) { cin.clear(); // clear error condition cin.ignore(100,'\n'); // remove characters cout << "Please enter an integer value for position " << i + 1 << " of the array. Number = "; cin >> num; myArray[i] = num; } //Test new value for uniqueness for(int j=0; j<i; ++j) { if(j != i) { if(myArray[i] == myArray[j]) unique = false; } } if(!unique) { cout << "Please re-enter number " << i + 1 << ". Duplicate numbers are not allowed." << endl; i--; } } //Display whats in the array... for(int i = 0; i < size; ++i) { cout << "Item In Element " << i + 1 << " of the array = : " << myArray[i] << endl; } //Delete the array delete[] myArray; return 0; } Ignore the end for now, after the display of the array, I'm still working on the first portion. So far I've managed to make it so that the user can enter a value for the array length, and then enter the various values for the array. I've made it so that the user will have enter a valid integer (non-zero, non-character, non-negative for array size. non-character, non-decimal for number). For some reason, when I run the program, after the program outputs the first cout statement, it just sits there waiting for a user input instead of displaying the second cout.
WOO, I'M FUCKING I think I got it. Now I just have to do my graphs, calculations, and test cases. Code: // Homework 2.cpp : Defines the entry point for the console application. // #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } #include <iostream> #include <string> #include <sstream> #include <math.h> using namespace std; int main() { float size = 0; //size must be an integer, however the declaration of size as float allows the while loop below to filter out any user intput float number. This is better than the float being cast to an int by the program, because the user is made aware of their error, and a message will appear. float A = 0.5; //A must be an integer, however the declaration of A as float allows the while loop below to filter out any user intput float number. This is better than the float being cast to an int by the program, because the user is made aware of their error, and a message will appear. bool match = false; //Create an Array of user input size cout << "Enter Array Size" << endl; cout << "Please enter an integer value greater than or equal to 1. Size = "; cin >> size; while(size <1 || size - floor(size) != 0 || !(cin.good())) // testing for Integer only input { cin.clear(); // clear error condition cin.ignore(100,'\n'); // remove characters cout << "Please enter an integer value greater than or equal to 1. Size = "; cin >> size; } //Create the array with the size the user input int *LIST = new int[size]; //Populate the array with user input for(int i = 0; i < size; ++i) { float num = 0.5; //num must be an integer, however the declaration of num as float allows the while loop below to filter out any user intput float number. This is better than the float being cast to an int by the program, because the user is made aware of their error, and a message will appear. bool unique = true; //Fill position i of the Array from user input cout << "\nEnter Integer: " << endl; while(num==0.5 || !(cin.good())) { cin.clear(); // clear error condition cin.ignore(100,'\n'); // remove characters cout << "Please enter an integer value for position " << i + 1 << " of the array. Number = "; cin >> num; LIST[i] = num; } //Test new value for uniqueness for(int j=0; j<i; ++j) { if(j != i) { if(LIST[i] == LIST[j]) unique = false; } } if(!unique) { cout << "Please re-enter number " << i + 1 << ". Duplicate numbers are not allowed." << endl; i--; } } //Display whats in the array... for(int i = 0; i < size; ++i) { cout << "Item In Element " << i << " of the array = : " << LIST[i] << endl; } //Capture user input for integer to search with cout << "\nEnter Integer 'A'. 'A' will be used to search the Array and check for a match."; while(A == 0.5 || !(cin.good())) // testing for Integer only input { cin.clear(); // clear error condition cin.ignore(100,'\n'); // remove characters cout << "\nPlease enter an integer value. 'A' = "; cin >> A; } //Test A vs LIST array cout << "\nSearching Array for variable 'A'" << endl; for(int i = 0; i < size; ++i) { if(LIST[i] == A) { match = true; cout << "Variable 'A' was found in Array at LIST[" << i << "]" << endl; break; } } if(match==false) { cout << "Variable 'A' was not in LIST." << endl; } //Delete the array delete[] LIST; system("PAUSE"); return 0; } Not bad for not knowing the fucking coding language when I woke up this morning (any more than the tiny bit we did before) and having to write something from scratch.
Good job! Sadly, the last bit of programming I did was in College, and it was C++. And I only just barely did enough to get a good-ish passing grade on the exams.
GDI, I don't think I'm done. Was showing it to the wife last night and it accepted a decimal value entry when filling in the array.
Code: • get_int Program Graph • get_int Cyclomatic Complexity V(G) = E – N + 2 V(G) = 8-7+2 V(G) = 3 • Basis Path Set 1. 1, 2, 3, 4, 5, 6 2. 1, 2, 3, 4, 7, 2, 3, 4, 5, 6 3. 1, 2, 3, 4, 5, 7, 3, 4, 5, 6 • Test Cases Test Case 1 Purpose: Testing Independent Path 1 – Happy path, input given by user is an Integer Conditions: 1. While(true) 2. ss >> out 3. ss >> in Inputs: in = 4 Expected Results: Variable size in main is given the value of 4 Results: Passed, size set to 4 Note: Cannot be tested independently without running main. Test Case 2 Purpose: Testing Independent Path 2 – User input was not a valid convertion to integer in the first pass Conditions: 1. While(true) 2. (ss >> out) 3. !(ss >> in) Inputs: in = a, 4 Expected Results: Variable size in main is given the value of 4 Results: Passed, size set to 4 Note: Cannot be tested independently without running main. Test Case 3 Purpose: Testing Independent Path 3 – User input was unconverted to integer in the first pass Conditions: 4. While(true) 5. (ss >> out) 6. !(ss >> in) Inputs: in = 4.5, 4 Expected Results: Variable size in main is given the value of 4 Results: Passed, size set to 4 Note: Cannot be tested independently without running main. • main Program Graph • main Cyclomatic Complexity V(G) = E – N + 2 V(G) = 23-16+2 V(G) = 9 • Basis Path Set 1. 1, 2, 10, 11, 14, 16 2. 1, 2, 3, 4, 8, 10, 11, 14, 16 3. 1, 2, 3, 4, 5, 8, 10, 11, 14, 16 4. 1, 2, 3, 4, 5, 6, 8, 10, 11, 14, 16 5. 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 14, 16 6. 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 14, 16 7. 1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 14, 16 8. 1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 16 9. 1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16 • Test Cases Test Case 1 Purpose: Testing Independent Path 1 – shortest path Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int i = 0; i < size; ++i) 3. if(match==false) Inputs: No possible inputs Expected Results: Cannot be run without changes made in code. Results: Note: Cannot be tested independently with User input. Test Case 2 Purpose: Testing Independent Path 2 – User input to “size” variable Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(!unique) 4. for(int i = 0; i < size; ++i) 5. if(match==false) Inputs: size = 4.5, a, 4 Expected Results: Node 3 executes function get_int for valid value of size Results: Error handling works correctly for input values 4.5, and a. Code only executes for value 4. Note: Cannot be tested independently with User input. Must put break point after node 3. Test Case 3 Purpose: Testing Independent Path 3 – test covers if(j != i) Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(j != i) 4. if(!unique) 5. for(int i = 0; i < size; ++i) 6. if(match==false) Inputs: Expected Results: Cannot be run without changes made in code. i and j start equal and only become unequal after running nodes 6 and 7, which are not part of this path. Must cycle through the for loop until j is greater than i, which can’t be done in this path. Results: Note: Cannot be tested independently with User input. Test Case 4 Purpose: Testing Independent Path 4 – test covers if(LIST[i] == LIST[j]). Value entered by User for second value in array is NOT the same as the first. Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(j != i) 4. if(LIST[i] == LIST[j]) 5. if(!unique) 6. for(int i = 0; i < size; ++i) 7. if(match==false) Inputs: size = 2; num = 1, 2 Expected Results: Cannot be run without changes made in code. Results: Note: Cannot be tested independently with User input. Must put break point after node 10. Test Case 5 Purpose: Testing Independent Path 5 – test covers if(LIST[i] == LIST[j]) being true and if(!unique) being false. Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(j != i) 4. if(LIST[i] == LIST[j]) 5. if(!unique) 6. for(int i = 0; i < size; ++i) 7. if(match==false) Inputs: Expected Results: Cannot be run without changes made in code. There are no values that pass Condition 4 but fail Condition 5. Results: Note: Cannot be tested independently with User input. Test Case 6 Purpose: Testing Independent Path 6 – test covers if(LIST[i] == A) being false. Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(j != i) 4. if(LIST[i] == LIST[j]) 5. if(!unique) 6. for(int i = 0; i < size; ++i) 7. if(LIST[i] == A) 8. if(match==false) Inputs: size = 2; num = 1, 1, 2 Expected Results: Cannot be run without changes made in code. When entering 1 for the second value of the array, an error will be given and prompt the user to enter a valid number that is not a duplicate. Results: Pass Note: Cannot be tested independently with User input. Must put break point after node 10. Test Case 7 Purpose: Testing Independent Path 7 – test covers if(LIST[i] == A) which must be true and if(match==false) which must be false. Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(j != i) 4. if(LIST[i] == LIST[j]) 5. if(!unique) 6. for(int i = 0; i < size; ++i) 7. if(match==false) Inputs: Expected Results: Cannot be run without changes made in code. There are no values that pass Condition 4 but fail Condition 5. Results: Note: Cannot be tested independently with User input. Test Case 8 Purpose: Testing Independent Path 8 –Test covers if(LIST[i] == A) which must be true and if(match==false) which must be false. This is the “happy path”, where the user inputs only approved values and is able to input a value for A which is found within the array. Conditions: 1. for(int i = 0; i < size; ++i) 2. for(int j=0; j<i; ++j) 3. if(j != i) 4. if(LIST[i] == LIST[j]) 5. if(!unique) 6. for(int i = 0; i < size; ++i) 7. if(match==false) Inputs: size = 2, num = 1, 2; A = 2 Expected Results: Cannot be run without changes made in code. Program will return the result that A was found within the array, in “LIST[1]”. Results: Pass Test Case 9 Purpose: Testing Independent Path 9 – test covers if(LIST[i] == LIST[j]) and if(!unique). Both conditions must be true. Test also covers if(LIST[i] == A) and if(match==false), which must both be false. Conditions: 8. for(int i = 0; i < size; ++i) 9. for(int j=0; j<i; ++j) 10. if(j != i) 11. if(LIST[i] == LIST[j]) 12. if(!unique) 13. for(int i = 0; i < size; ++i) 14. if(match==false) Inputs: size = 2, num = 1, 2; A = 4 Expected Results: Cannot be run without changes made in code. Program will return the result that A was not found within the array, there was no match. Results: Pass // Homework 2.cpp : Defines the entry point for the console application. // #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } #include <iostream> #include <string> #include <sstream> #include <math.h> using namespace std; int get_int(char *message) { //---------Node 1---------// int out; string in; //---------Node 1---------// //---------Node 2---------// while(true) { //---------Node 2---------// //---------Node 3---------// cout << message; getline(cin,in); stringstream ss(in); //covert input to a stream for conversion to int //---------Node 3---------// //---------Node 4---------// if(ss >> out && !(ss >> in)) { //(ss >> out) checks for valid conversion to integer //---------Node 4---------// //---------Node 5---------// //!(ss >> in) checks for unconverted input and rejects it //---------Node 5---------// //---------Node 6---------// return out; } //---------Node 6---------// //---------Node 7---------// cin.clear(); //in case of a cin error, like eof() -- prevent infinite loop cerr << "\nInvalid input. Please try again.\n"; //if you get here, it's an error //---------Node 7---------// } } int main() { //---------Node 1---------// int size; int A; bool match = false; //Create an Array of user input size cout << "Enter Array Size" << endl; size = get_int("Please enter an integer value greater than or equal to 1. Size = "); //Create the array with the size the user input int *LIST = new int[size]; //---------Node 1---------// //Populate the array with user input //---------Node 2---------// for(int i = 0; i < size; ++i) //---------Node 2---------// { //---------Node 3---------// int num; bool unique = true; //Fill position i of the Array from user input cout << "\nPlease enter an integer value for position " << i + 1 << " of the array." << endl; LIST[i] = get_int("Number = "); //---------Node 3---------// //Test new value for uniqueness //---------Node 4---------// for(int j=0; j<i; ++j) //---------Node 4---------// { //---------Node 5---------// if(j != i) //---------Node 5---------// { //---------Node 6---------// if(LIST[i] == LIST[j]) //---------Node 6---------// //---------Node 7---------// unique = false; //---------Node 7---------// } } //---------Node 8---------// if(!unique) //---------Node 8---------// { //---------Node 9---------// cout << "Please re-enter number " << i + 1 << ". Duplicate numbers are not allowed." << endl; i--; //---------Node 9---------// } } //Capture user input for integer to search with //---------Node 10---------// cout << "\nEnter Integer 'A'. 'A' will be used to search the Array and check for a match."; A = get_int("\nPlease enter an integer value. 'A' = "); cout << "\nSearching Array for variable 'A'" << endl; //---------Node 10---------// //Test A vs LIST array //---------Node 11---------// for(int i = 0; i < size; ++i) //---------Node 11---------// { //---------Node 12---------// if(LIST[i] == A) //---------Node 12---------// { //---------Node 13---------// match = true; cout << "Variable 'A' was found in Array at LIST[" << i << "]" << endl; break; //---------Node 13---------// } } //---------Node 14---------// if(match==false) //---------Node 14---------// { //---------Node 15---------// cout << "Variable 'A' was not in LIST." << endl; //---------Node 15---------// } //---------Node 16---------// system("PAUSE"); return 0; //---------Node 16---------// } I'm not going to bother posting the images for the program graphs, cause they can suck my dick. Ended up splitting it in to 2 functions instead of one. Hopefully they don't try to put a negative number in for the array size when grading.
AAAAHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!! I think my only option is the term paper, which I've never written, and have no clue how to find a topic for.
Suspicious package found on campus so some of it was evacuated... maybe that's why neither I nor my proctor have heard from the prof. about wtf to do for my midterm today? Turns out it was benign.
Does this gibberish mean anything to you coder types? "Discuss how to test integration of methods in an object class?"
Google Fu and that makes sense with the description here. Class (computer programming) Not sure if that helps. Maybe someone who actually KNOWS how to program would be more help, as I know very little about programming. And I hate in, any class, when they give you an assignment and expect you to know what the question is asking for.
Wish I could help Dihm but my knowledge of coding doesn't extend beyond a simple intro to C++ course I took 2 years ago and a shit ton of java I did this year for robotics