SlideShare a Scribd company logo
1 of 9
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 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 ++)
{
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
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");
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

More Related Content

Similar to I have question in c++ program I need the answer as soon as possible.docx

Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptxNelyJay
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxrohinitalekar1
 
UNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt pptUNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt pptSuganthiDPSGRKCW
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...AntareepMajumder
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202Mahmoud Samir Fayed
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
Notes3
Notes3Notes3
Notes3hccit
 
The Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldThe Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 

Similar to I have question in c++ program I need the answer as soon as possible.docx (20)

Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Arrays
ArraysArrays
Arrays
 
UNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt pptUNIT III PYTHON.pptx python basic ppt ppt
UNIT III PYTHON.pptx python basic ppt ppt
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
Unit 2
Unit 2Unit 2
Unit 2
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Notes3
Notes3Notes3
Notes3
 
Array and string
Array and stringArray and string
Array and string
 
The Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldThe Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and Fold
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
STL in C++
STL in C++STL in C++
STL in C++
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Arrays
ArraysArrays
Arrays
 

More from delciegreeks

Final Project Organizational Level of AnalysisYou are to rese.docx
Final Project Organizational Level of AnalysisYou are to rese.docxFinal Project Organizational Level of AnalysisYou are to rese.docx
Final Project Organizational Level of AnalysisYou are to rese.docxdelciegreeks
 
Final Project (Week Eight)Required Elements of Final Projec.docx
Final Project (Week Eight)Required Elements of Final Projec.docxFinal Project (Week Eight)Required Elements of Final Projec.docx
Final Project (Week Eight)Required Elements of Final Projec.docxdelciegreeks
 
Final PaperFollows all Project assignment details and technical re.docx
Final PaperFollows all Project assignment details and technical re.docxFinal PaperFollows all Project assignment details and technical re.docx
Final PaperFollows all Project assignment details and technical re.docxdelciegreeks
 
Final PaperGlobal climate change has become one of the top env.docx
Final PaperGlobal climate change has become one of the top env.docxFinal PaperGlobal climate change has become one of the top env.docx
Final PaperGlobal climate change has become one of the top env.docxdelciegreeks
 
Final PaperYour good friends have just adopted a four-year-old chi.docx
Final PaperYour good friends have just adopted a four-year-old chi.docxFinal PaperYour good friends have just adopted a four-year-old chi.docx
Final PaperYour good friends have just adopted a four-year-old chi.docxdelciegreeks
 
Final Paper To complete this assignment, read through the scenario.docx
Final Paper To complete this assignment, read through the scenario.docxFinal Paper To complete this assignment, read through the scenario.docx
Final Paper To complete this assignment, read through the scenario.docxdelciegreeks
 
Final Argument Paper The Case of the West Memphis ThreeIn 1994,.docx
Final Argument Paper The Case of the West Memphis ThreeIn 1994,.docxFinal Argument Paper The Case of the West Memphis ThreeIn 1994,.docx
Final Argument Paper The Case of the West Memphis ThreeIn 1994,.docxdelciegreeks
 
Final Essay Exam for English 2328 There is no grace period for the.docx
Final Essay Exam for English 2328 There is no grace period for the.docxFinal Essay Exam for English 2328 There is no grace period for the.docx
Final Essay Exam for English 2328 There is no grace period for the.docxdelciegreeks
 
fin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docx
fin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docxfin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docx
fin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docxdelciegreeks
 
Film CaramelYear______________Director ________________.docx
Film CaramelYear______________Director ________________.docxFilm CaramelYear______________Director ________________.docx
Film CaramelYear______________Director ________________.docxdelciegreeks
 
Film Omar Year______________Director ________________Desc.docx
Film Omar Year______________Director ________________Desc.docxFilm Omar Year______________Director ________________Desc.docx
Film Omar Year______________Director ________________Desc.docxdelciegreeks
 
Fiduciary DutiesWrite a short essay, between 400 and 500 words, re.docx
Fiduciary DutiesWrite a short essay, between 400 and 500 words, re.docxFiduciary DutiesWrite a short essay, between 400 and 500 words, re.docx
Fiduciary DutiesWrite a short essay, between 400 and 500 words, re.docxdelciegreeks
 
Figure the tax using the schedule D tax worksheet (pg 23 of workpape.docx
Figure the tax using the schedule D tax worksheet (pg 23 of workpape.docxFigure the tax using the schedule D tax worksheet (pg 23 of workpape.docx
Figure the tax using the schedule D tax worksheet (pg 23 of workpape.docxdelciegreeks
 
Fiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docx
Fiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docxFiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docx
Fiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docxdelciegreeks
 
Film music is incredibly important in helping to make a movie become.docx
Film music is incredibly important in helping to make a movie become.docxFilm music is incredibly important in helping to make a movie become.docx
Film music is incredibly important in helping to make a movie become.docxdelciegreeks
 
feld is a shoemaker who came to America from Poland. He has a helper.docx
feld is a shoemaker who came to America from Poland. He has a helper.docxfeld is a shoemaker who came to America from Poland. He has a helper.docx
feld is a shoemaker who came to America from Poland. He has a helper.docxdelciegreeks
 
FederalismThe system of federalism was instituted with the writing.docx
FederalismThe system of federalism was instituted with the writing.docxFederalismThe system of federalism was instituted with the writing.docx
FederalismThe system of federalism was instituted with the writing.docxdelciegreeks
 
Federalism and Intergovernmental relations are dominated by one key .docx
Federalism and Intergovernmental relations are dominated by one key .docxFederalism and Intergovernmental relations are dominated by one key .docx
Federalism and Intergovernmental relations are dominated by one key .docxdelciegreeks
 
Federal Reserve Banks directly affect the national economy byWhich.docx
Federal Reserve Banks directly affect the national economy byWhich.docxFederal Reserve Banks directly affect the national economy byWhich.docx
Federal Reserve Banks directly affect the national economy byWhich.docxdelciegreeks
 
feel free to send your handshake but any handshake more than $25 wil.docx
feel free to send your handshake but any handshake more than $25 wil.docxfeel free to send your handshake but any handshake more than $25 wil.docx
feel free to send your handshake but any handshake more than $25 wil.docxdelciegreeks
 

More from delciegreeks (20)

Final Project Organizational Level of AnalysisYou are to rese.docx
Final Project Organizational Level of AnalysisYou are to rese.docxFinal Project Organizational Level of AnalysisYou are to rese.docx
Final Project Organizational Level of AnalysisYou are to rese.docx
 
Final Project (Week Eight)Required Elements of Final Projec.docx
Final Project (Week Eight)Required Elements of Final Projec.docxFinal Project (Week Eight)Required Elements of Final Projec.docx
Final Project (Week Eight)Required Elements of Final Projec.docx
 
Final PaperFollows all Project assignment details and technical re.docx
Final PaperFollows all Project assignment details and technical re.docxFinal PaperFollows all Project assignment details and technical re.docx
Final PaperFollows all Project assignment details and technical re.docx
 
Final PaperGlobal climate change has become one of the top env.docx
Final PaperGlobal climate change has become one of the top env.docxFinal PaperGlobal climate change has become one of the top env.docx
Final PaperGlobal climate change has become one of the top env.docx
 
Final PaperYour good friends have just adopted a four-year-old chi.docx
Final PaperYour good friends have just adopted a four-year-old chi.docxFinal PaperYour good friends have just adopted a four-year-old chi.docx
Final PaperYour good friends have just adopted a four-year-old chi.docx
 
Final Paper To complete this assignment, read through the scenario.docx
Final Paper To complete this assignment, read through the scenario.docxFinal Paper To complete this assignment, read through the scenario.docx
Final Paper To complete this assignment, read through the scenario.docx
 
Final Argument Paper The Case of the West Memphis ThreeIn 1994,.docx
Final Argument Paper The Case of the West Memphis ThreeIn 1994,.docxFinal Argument Paper The Case of the West Memphis ThreeIn 1994,.docx
Final Argument Paper The Case of the West Memphis ThreeIn 1994,.docx
 
Final Essay Exam for English 2328 There is no grace period for the.docx
Final Essay Exam for English 2328 There is no grace period for the.docxFinal Essay Exam for English 2328 There is no grace period for the.docx
Final Essay Exam for English 2328 There is no grace period for the.docx
 
fin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docx
fin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docxfin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docx
fin 534 week 9 assignment #1Assignment 1 Financial Research Repor.docx
 
Film CaramelYear______________Director ________________.docx
Film CaramelYear______________Director ________________.docxFilm CaramelYear______________Director ________________.docx
Film CaramelYear______________Director ________________.docx
 
Film Omar Year______________Director ________________Desc.docx
Film Omar Year______________Director ________________Desc.docxFilm Omar Year______________Director ________________Desc.docx
Film Omar Year______________Director ________________Desc.docx
 
Fiduciary DutiesWrite a short essay, between 400 and 500 words, re.docx
Fiduciary DutiesWrite a short essay, between 400 and 500 words, re.docxFiduciary DutiesWrite a short essay, between 400 and 500 words, re.docx
Fiduciary DutiesWrite a short essay, between 400 and 500 words, re.docx
 
Figure the tax using the schedule D tax worksheet (pg 23 of workpape.docx
Figure the tax using the schedule D tax worksheet (pg 23 of workpape.docxFigure the tax using the schedule D tax worksheet (pg 23 of workpape.docx
Figure the tax using the schedule D tax worksheet (pg 23 of workpape.docx
 
Fiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docx
Fiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docxFiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docx
Fiero, Gloria K. Landmarks in Humanities. London Laurence King Publ.docx
 
Film music is incredibly important in helping to make a movie become.docx
Film music is incredibly important in helping to make a movie become.docxFilm music is incredibly important in helping to make a movie become.docx
Film music is incredibly important in helping to make a movie become.docx
 
feld is a shoemaker who came to America from Poland. He has a helper.docx
feld is a shoemaker who came to America from Poland. He has a helper.docxfeld is a shoemaker who came to America from Poland. He has a helper.docx
feld is a shoemaker who came to America from Poland. He has a helper.docx
 
FederalismThe system of federalism was instituted with the writing.docx
FederalismThe system of federalism was instituted with the writing.docxFederalismThe system of federalism was instituted with the writing.docx
FederalismThe system of federalism was instituted with the writing.docx
 
Federalism and Intergovernmental relations are dominated by one key .docx
Federalism and Intergovernmental relations are dominated by one key .docxFederalism and Intergovernmental relations are dominated by one key .docx
Federalism and Intergovernmental relations are dominated by one key .docx
 
Federal Reserve Banks directly affect the national economy byWhich.docx
Federal Reserve Banks directly affect the national economy byWhich.docxFederal Reserve Banks directly affect the national economy byWhich.docx
Federal Reserve Banks directly affect the national economy byWhich.docx
 
feel free to send your handshake but any handshake more than $25 wil.docx
feel free to send your handshake but any handshake more than $25 wil.docxfeel free to send your handshake but any handshake more than $25 wil.docx
feel free to send your handshake but any handshake more than $25 wil.docx
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
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