Given a two-dimensional array named number of three rows and four columns of type int, write
the single code statement that will both declare and initialize the array such that the first row is
initialized to 0, 1, 2, 3; the second row is initialized to 4, 5, 6, 7; and the third row is initialized to
8, 9, 10, 11.
Solution
#include
using namespace std;
int main() {
// your code goes here
int number[3][4] = {{0,1,2,3},{4,5,6,7},{8,9,10,11}};
cout << \"Content of number is : \" << endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout << number[i][j] << \" \" ;
}
cout << endl;
}
return 0;
}
OUTPUT:
Content of number is :
0 1 2 3
4 5 6 7
8 9 10 11.
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
How do I add another txt.file to this Im trying to add this to be.pdf
1. How do I add another txt.file to this? I'm trying to add this to below...can someone help me
please?
US;NONRESIDENT;123456;Jones;123 Cooper St;Arlington;Texas;76019;12345
INT;ACTIVE;A-654789;Degrassey;18 Love Lane;Dallas;Texas;75052;67123
INT;INACTIVE;A-543891;Franco;1201 Trail Road;Euless;Texas;74032;19814
US;RESIDENT;345123;Hughes;1803 Division;Fort Worth;Texas;76034;674532
US;RESIDENT;988776;Cooper;111 Marsh Lane;Bedford;Texas;76111;90906
INT;INACTIVE;B-577463;Patel;2218 Border St;Arlington;Texas;76015;81832
package writefiles;
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class WriteFiles {
private static Formatter output;
private static Scanner input;
public static void main(String[] args) {
ArrayList coursesList = new ArrayList();
writeTextFile();
readTextFile(coursesList);
for (Course c: coursesList){
System.out.println(c.toString());
}
writeSerFile(coursesList);
readSerFile();
}
4. try{
input = new ObjectInputStream(new FileInputStream(getFile()));
while(true){
obj = (Course)input.readObject();
System.out.println(obj.toString());
}
}
catch(EOFException eof){
}
catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
public static File getFile()
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.CANCEL_OPTION){
System.exit(1);
}
File fileName = fileChooser.getSelectedFile();
if ((fileName == null) || (fileName.getName().equals(""))){
JOptionPane.showMessageDialog(null, "Invalid Option",
5. "Invalid Option", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
return fileName;
}
}
Solution
We need to create new course constructor and new function to read file. And remaining function
remins same.
//course constructor should be
public course(String val1, String val2, String val3,String val4, String val5,String val6,String
val7,int val8, int val9){
// initialise these variables in course file
}
-------------------------------------------------------------------------------------------------
// now I am modifying in our exact file
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class WriteFiles {
private static Formatter output;
private static Scanner input;
public static void main(String[] args) {
ArrayList coursesList = new ArrayList();
writeTextFile();
readTextFile(coursesList);
readTextFileNew(coursesList); // calling seperate new method to read new format file