answersLogoWhite

0


Best Answer

Use an initialisation list:

std::array<std::pair<std::string,std::string>,10> students = {

{"Albert","Einstein"}, {"Billy", "Kidd"},

{"Charlie","Chaplin"}, {"David","Essex"},

{"Eric","Idle"}, {"Fred","Flintstone"},

{"Gary", "Gilmore"}, {"Harold","Lloyd"},

{"Ian","Fleming"}, {"Jack","Black"}

};

Alternatively, have the user input the information via std::cin (manual input or redirected from a file), or extract the data from an input stream.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How will initialize an array to names of 10 students?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


What is multidimensional array in c plus plus?

A multidimensional array in C or C++ is simply an array of arrays, or an array of an array of arrays, etc. for however many dimensions you want. int a; // not an array int a[10]; // ten int a's int a[10][20]; // twenty int a[10]'s, or 200 int a's int a[10][20][30]; // and so on and so forth...


What is the container object that holds a fixed number of values of single type?

There are multiple answers to this question, but the most basic one common to both Java and C is the array. An array is a simple structure that you initialize to a certain size and fill with data. Think of an array as a sort of list, where each element in the list is numbered starting from zero up to the list size minus one (or the array is zero-based, as it's also called). In Java: // 10 is the number of elements the array can hold int[] myIntArray = new int[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher will cause a runtime error in Java, which may stop your program. In C: // 10 is the number of elements the array can hold int myIntArray[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher results in a buffer overflow in C (and C++). Note that in C, this won't throw errors like they do in Java, and this can and very likely will cause your program to have random bugs and possibly even crash from a segmentation fault, so be a bit more careful about using arrays in C.

Related questions

Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


What is an error in java?

An error or more commonly known as an Exception is a situation where the java program behaves in a way it is not supposed to do so. It is a problem in the code that is causing the JVM to terminate or throw error messages in the console. Ex: When you initialize an array list with 10 elements and try to access the 11th element in the array list you will get an array index out of bounds exception.


How arrays are created in java?

Arrays are created just like other variables in Java. Ex: int[] a; // declares an array of integers a = new int[10]; // allocates memory for 10 integers a[0] = 100; // initialize first element a[1] = 200; // initialize second element Arrays are homogenous data types and hence they can contain values of only one type. If you create an integer array it can hold only integer data type values. If you try to assign values to nonexistent locations like a[15] it will throw an index out of bounds exception.


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


How do make 10student name and his remarks in q-basic?

' '*** PROGRAM: Collecting student data: names/marks. ' '*** Create 2 array variables to store each students name/marks... DIM students$(10), marks$(10) '*** SCREEN ONE/Collect the data... CLS '...(CL)ear the Output (S)creen '*** print heading... PRINT "PROGRAM: Collecting each student names/marks..." PRINT '*** A FOR/NEXT loop is used to collect each individual students data... FOR eachStudentNo% = 1 TO 10 '*** Get each students names/marks 'by typing these values in from the keyboard.... PRINT eachStudentNo%; "&gt;" INPUT " Enter student name"; students$(eachStudentNo%) INPUT "Enter student marks"; marks$(eachStudentNo%) NEXT '*** SCREEN TWO: Output the collected data... CLS '...(CL)ear the Output (S)creen '*** Print headings... PRINT "Student No.", "Student Name", "Student Marks" PRINT '*** FOR/NEXT loop is used to print out the 2 array student 'name/marks' values... FOR eachStudentNo% = 1 TO 10 '*** print out each students 'number/name/mark' values... PRINT eachStudentNo%, PRINT students$(eachStudentNo%), PRINT marks$(eachStudentNo%) NEXT END '...END of program/halt program code execution


What is multidimensional array in c plus plus?

A multidimensional array in C or C++ is simply an array of arrays, or an array of an array of arrays, etc. for however many dimensions you want. int a; // not an array int a[10]; // ten int a's int a[10][20]; // twenty int a[10]'s, or 200 int a's int a[10][20][30]; // and so on and so forth...


What is the container object that holds a fixed number of values of single type?

There are multiple answers to this question, but the most basic one common to both Java and C is the array. An array is a simple structure that you initialize to a certain size and fill with data. Think of an array as a sort of list, where each element in the list is numbered starting from zero up to the list size minus one (or the array is zero-based, as it's also called). In Java: // 10 is the number of elements the array can hold int[] myIntArray = new int[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher will cause a runtime error in Java, which may stop your program. In C: // 10 is the number of elements the array can hold int myIntArray[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher results in a buffer overflow in C (and C++). Note that in C, this won't throw errors like they do in Java, and this can and very likely will cause your program to have random bugs and possibly even crash from a segmentation fault, so be a bit more careful about using arrays in C.


How do you declare an array alpha of 10 rows and 20 columns of type int?

int array[2][10][20];


How do you find the address of Three dimenesional array?

let the array be "int a[10][10][10];" the address of this multidimensional array can be extracted by the following codes in printf statement. 1. printf("%p", &amp;a[0][0][0]); 2. printf("%p",a); "a" gives the base-address of array


How do you declare and initialize constant arrays?

example in C: const int a [] = {10, 20, 40, 80};


How can you initialize an array in Java?

If you refering to Object then String[] something=new String[2]; Here you have to remember that something only allocated space for 2 String object but it did not created them yet. By default Objects are intantiated to null so if you try to print the content of an array System.out.println(something[0]);//print null System.out.println(something[0].toLowerCase()); Throws NullPointerException Couple other ways to create Arrays In java String[] something=new String[]{"Me","You"}; String[] something={"Me", "You"};