CSCI-1170-01 Askar Nurbekov Code Completion

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given the following class studentType Member functions: // Receives and sets the values of the data members setData(name, grade) // Returns student's name getName() // Returns student's grade getGrade() Data members: // Student's name name // Student's grade grade Complete the following code to declare the class and use it in main(): [A] studentType { [B] void setData(string, int); string getName() const; int getGrade() const; [C] string name; int grade; }; int main() { // Declare two objects to represent students [D] freshman1, freshman2; // Declare a variable to hold a name string sname; // Declare a variable to hold a grade int sgrade; // Prompt the user to enter name and grade of the first student cout << "Enter name and grade of the first student: "; // Get them from the keyboard and store them in corresponding variables cin >> sname >> sgrade; // Set the data members of the first student [E](sname, sgrade); // Prompt the user to enter name and grade of the second student cout << "Enter name and grade of the second student: "; // Get them from the keyboard and store them in corresponding variables cin >> sname >> sgrade; // Set the data members of the second student [F](sname, sgrade); cout << endl; // Display the name of the first student cout << [G](); // If the grade of the first student is higher than the grade of the second student // display the corresponding message according to the above specifications if ([H]() > [I]()) cout << " got a higher grade than "; else cout << " got a lower grade than "; // Display the name of the second student cout << [J]() << endl; return 0; }

Given the following class studentType Member functions: // Receives and sets the values of the data members setData(name, grade) // Returns student's name getName() // Returns student's grade getGrade() Data members: // Student's name name // Student's grade grade Complete the following code to declare the class and use it in main(): class studentType { public: void setData(string, int); string getName() const; int getGrade() const; private: string name; int grade; }; int main() { // Declare two objects to represent students studentType freshman1, freshman2; // Declare a variable to hold a name string sname; // Declare a variable to hold a grade int sgrade; // Prompt the user to enter name and grade of the first student cout << "Enter name and grade of the first student: "; // Get them from the keyboard and store them in corresponding variables cin >> sname >> sgrade; // Set the data members of the first student freshman1.setData(sname, sgrade); // Prompt the user to enter name and grade of the second student cout << "Enter name and grade of the second student: "; // Get them from the keyboard and store them in corresponding variables cin >> sname >> sgrade; // Set the data members of the second student freshman2.setData(sname, sgrade); cout << endl; // Display the name of the first student cout << freshman1.getName(); // If the grade of the first student is higher than the grade of the second student // display the corresponding message according to the above specifications if (freshman1.getGrade() > freshman2.getGrade()) cout << " got a higher grade than "; else cout << " got a lower grade than "; // Display the name of the second student cout << freshman2.getName() << endl; return 0; }

Write C++ statements to: 1) Declare a two dimensional array with 10 rows and 10 columns of whole numbers. 2) Fill all array elements with a zero except those which are on the diagonal that goes from the right-top corner to the left-bottom corner of the array which must be filled with a one (see the example below for a 5x5 array). 3) Print the array. Example: 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 Complete the following code to implement the solution: // Declare constant variable SIZE to hold the number of rows and columns of the array !!!A!!!; // Returns the array (mesh) filled with the 0's and 1's void createGrid( !!!B!!! ) { // Use nested for loops to fill mesh according to the above specifications for (int row = 0; row < SIZE; ++row) { for (int col = 0; col < SIZE; ++col) { if (col == !!!C!!!) mesh !!!D!!! = 1; else mesh !!!E!!! = 0; } } } // Receives the array (mesh) to be printed void printGrid( !!!F!!! ) { // Use nested for loops to print mesh according to the above specifications for (int row = 0; row < SIZE; ++row) { for (int col = 0; col < SIZE; ++col) { cout << setw(2) << mesh !!!G!!!; } cout << endl; } } int main() { // Declare the two dimensional array named grid int grid !!!H!!!; // Call the function to create the grid createGrid(

Write C++ statements to: 1) Declare a two dimensional array with 10 rows and 10 columns of whole numbers. 2) Fill all array elements with a zero except those which are on the diagonal that goes from the right-top corner to the left-bottom corner of the array which must be filled with a one (see the example below for a 5x5 array). 3) Print the array. Example: 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 Complete the following code to implement the solution: // Declare constant variable SIZE to hold the number of rows and columns of the array const int SIZE = 5; !!!A!!! // Returns the array (mesh) filled with the 0's and 1's void createGrid(int mesh[SIZE][SIZE]) !!!B!!! { // Use nested for loops to fill mesh according to the above specifications for (int row = 0; row < SIZE; ++row) { for (int col = 0; col < SIZE; ++col) { if (col == ) !!!C!!! mesh [row][col] = 1; !!!D!!! else mesh [row][col] = 0; !!!E!!! } } } // Receives the array (mesh) to be printed void printGrid(int mesh[SIZE][SIZE]) !!!F!!! { // Use nested for loops to print mesh according to the above specifications for (int row = 0; row < SIZE; ++row) { for (int col = 0; col < SIZE; ++col) { cout << setw(2) << mesh [row][col]; !!!G!!! } cout << endl; } } int main() { // Declare the two dimensional array named grid int grid [SIZE][SIZE]; !!!H!!! // Call the function to create the grid createGrid(grid); !!!I!!! // Call the function to print the grid printGrid(grid); !!!J!!! return 0; }


Kaugnay na mga set ng pag-aaral

CH 3 Working with Financial Statements

View Set

Ch. 25 Gastrointestinal Dysfunction Evolve Quiz

View Set

WHAP Unit V Study Guide - The Globe Encompassed, 1500-1750

View Set

Erikson's Theory of Identity Development

View Set

Frankenstein Quotes - chapters 7 - 9

View Set