I have question in c++ program I need the answer as soon as possible
I attached the file
1.1
Nested Loops – Lab3C.cpp
Loops often have loops inside them. These are called “nested” loops. In this exercise you will finish a nested loop that reads lines of numbers from a file and computes and prints out the sum of each line.
//C++ Lab3C.cpp
//
//
//
//1. [include required header files]//
using namespace std;
int main()
{
[2. Declare required variables]
try
{
//3> put your file name & Open file as an input mode
ifstream Openfile(" “);
//4> If file doesn't exist then throw error number
if(Openfile.good())
{
while( getline(Openfile, sLine)) //Outer While Loop Condition
{
cout << "The Contents of line sLine" << sLine << "\n";
stringstream Str(sLine);
while (Str >> temp ) //Inner While Loop Condition
{
cout << "String ~to double" << temp;
}// Inner while Loop
} //Outer While Loop
Openfile.close();
//3> Catch the error number and display message
}
else {
throw 10;
}
} //if
catch(int e)
{
cout << "File Not found " << e << endl;
}
//system("pause"); //Pause
return 0;
}//main
1.2
Once you have completed the program, run it on the input file below:
Lab4C.in
10 20 30 40 50
60 70 80 90.0
11 13.0
20 40 70 19.0
Lab4C.out or Lab4C.doc with screen shot
Read Line 0 10.0 Sum 10.0
Read Line 0 20.0 Sum 30.0
Read Line 0 30.0 Sum 60.0
Read Line 0 40.0 Sum 100.0
Read Line 0 50.0 Sum 150.0
…..
Read Line 3 20.0 Sum 20.0
Read Line 3 40.0 Sum 60.0
Read Line 3 70.0 Sum 130.0
Read Line 3 19.0 Sum 149.0
1.3
Upload your four files (Lab3A.cpp, Lab3B.cpp, Lab3C.cpp and Lab3C.doc) as one single zip file named “Lab3ABC.zip”)
2.
Lab3D – Two Dimensional Arrays
2.1
Declaring 2D arrays
In C++, to make a 2D array, we simply declare an array where the type is an array. To see how this works, first look at how we create an int array with 10 elements. One might type
int arr1D[ 10] ;
What the above code actually does is create a new “int Array” that reserves enough space to store 10 integers. For creating a 2D arrays, we can make an array of them, by appending another set of square brackets:
int arr2D[3][7];
This declares a two dimensional array of ints with 3 rows and 7 columns. By convention, we think of the array as being indexed in “Row Major Order”, which means that the row (y value) comes before the column (x value).
Thus, visually, the array looks like this:
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
The top left element is at position [0][0], and the bottom right element is at position [2][6]. The array elements are initialized just as in the 1D case ( Numerics are set to 0, and object types are set to null). To access one of the elements of a 2D array, we use double bracket notation again, so we can write
arr2D[0][1] = 1;
arr2D[2][3] = 4;
This would give us the array:
0 1 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 4 0 0 0
If we want to visit or process every ele ...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
I have question in c++ program I need the answer as soon as possible.docx
1. I have question in c++ program I need the answer as soon as
possible
I attached the file
1.1
Nested Loops – Lab3C.cpp
Loops often have loops inside them. These are called “nested”
loops. In this exercise you will finish a nested loop that reads
lines of numbers from a file and computes and prints out the
sum of each line.
//C++ Lab3C.cpp
//
//
//
//1. [include required header files]//
using namespace std;
int main()
{
[2. Declare required variables]
2. try
{
//3> put your file name & Open file as an input mode
ifstream Openfile(" “);
//4> If file doesn't exist then throw error number
if(Openfile.good())
{
while( getline(Openfile, sLine)) //Outer While Loop Condition
{
cout << "The Contents of line sLine" << sLine << "n";
stringstream Str(sLine);
while (Str >> temp ) //Inner While Loop Condition
{
cout << "String ~to double" << temp;
}// Inner while Loop
3. } //Outer While Loop
Openfile.close();
//3> Catch the error number and display message
}
else {
throw 10;
}
} //if
catch(int e)
{
cout << "File Not found " << e << endl;
}
//system("pause"); //Pause
return 0;
}//main
1.2
Once you have completed the program, run it on the input file
below:
Lab4C.in
4. 10 20 30 40 50
60 70 80 90.0
11 13.0
20 40 70 19.0
Lab4C.out or Lab4C.doc with screen shot
Read Line 0 10.0 Sum 10.0
Read Line 0 20.0 Sum 30.0
Read Line 0 30.0 Sum 60.0
Read Line 0 40.0 Sum 100.0
Read Line 0 50.0 Sum 150.0
…..
Read Line 3 20.0 Sum 20.0
Read Line 3 40.0 Sum 60.0
Read Line 3 70.0 Sum 130.0
Read Line 3 19.0 Sum 149.0
1.3
Upload your four files (Lab3A.cpp, Lab3B.cpp, Lab3C.cpp and
Lab3C.doc) as one single zip file named “Lab3ABC.zip”)
5. 2.
Lab3D – Two Dimensional Arrays
2.1
Declaring 2D arrays
In C++, to make a 2D array, we simply declare an array where
the type is an array. To see how this works, first look at how we
create an int array with 10 elements. One might type
int arr1D[ 10] ;
What the above code actually does is create a new “int Array”
that reserves enough space to store 10 integers. For creating a
2D arrays, we can make an array of them, by appending another
set of square brackets:
int arr2D[3][7];
This declares a two dimensional array of ints with 3 rows and 7
columns. By convention, we think of the array as being indexed
in “Row Major Order”, which means that the row (y value)
comes before the column (x value).
Thus, visually, the array looks like this:
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
The top left element is at position [0][0], and the bottom right
6. element is at position [2][6]. The array elements are initialized
just as in the 1D case ( Numerics are set to 0, and object types
are set to null). To access one of the elements of a 2D array, we
use double bracket notation again, so we can write
arr2D[0][1] = 1;
arr2D[2][3] = 4;
This would give us the array:
0 1 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 4 0 0 0
If we want to visit or process every element of a 2D array, we
need a nested for loop to do it. Generally, when you iterate over
a 2D array, you want to do it in row major order, because this is
more memory efficient. The reason why is that adjacent
elements in a row are stored contiguously (one after another) in
memory. Another reason, for an English speaker, is that this is
the same order your read a book—top to bottom, left to right.
The following code iterates over arr2D, changing each value to
1:
const int ROW =3;
const int COL =7;
int arr2D[3][7];
for(int r=0; r < ROW ; r ++)
7. {
for(int c =0; COL; r++)
{
arr2D[r][c] = 1;
}
}
I'm using the variables "r" and "c" because they iterate of the
rows and columns of the array, respectively. The outer loop
iterates over all the rows, and the inner loop iterates over all the
columns in a single row. Notice how the row index (r) comes
before the column index (c).
Also, notice how the loop bounds are handled in the interior
loop. While the outer loop goes from 0 to ROW, the inner loop
goes from 0 to COL.
Type in
, and finish the following program, which computes and prints
an addition table using nested loops and a 2D array:
//C++ Lab3B.cpp
//
//
//
#include
8. using namespace std;
typedef int* IntArrayPtr;
int main( )
{
//Propt user for input
cout << "Please Enter your Size of An Array n";
//Read an integer from the keyboard & save it to the int
variable.
//[1. Add Code Here ]
//[2. Create one-dimensional dynamic array]
//[3. Create two-dimensional dynamic array]
//Fill out the table using a netsted loop so that
//Table[r][c] = r + c;
//[4. Add Code Here]
//Itrate over the table, printing each value
//so that columns align(hint: use a nested loop )
//[5. Add Code Here]
//[6. Delete dynamic array]
system("pause");
9. return 0;
}//End of main
When finished, with an input value of 4, the program should
print something like:
0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6