you will decide what you will do. The idea is to make you think about what all c
ID: 643373 • Letter: Y
Question
you will decide what you will do. The idea is to make you think about what all can you do with the programming you have learned so far and to play around with it.
The program, however, must have:
An extra function besides "main" (or whatever you call it)
At least one decision structure (if or if-else or if-elif-else)
At least one for loop
It must access at least one file for reading and/or writing
Your program must serve some purpose, i.e. it should not merely be a bunch of statements. The purpose need not be something complex. Anything at the level of the programming exercises at the end of chapters should be good, you may also do one of those or their variations but it must satisfy the above conditions.
Explanation / Answer
#include
#include
#include
void getData();
void display();
int age;
char name[25];
char add[26];
int marks[3];
int main()
{
char c;
getData();
ofstream myfile("example.txt",ios::app);
cout<<"Do you want to write the details to a file Please Enter Y or N:";
cin>>c;
if(c=='Y')
{
myfile< myfile<<"Name:"< myfile<<"Age:"< myfile<<"Add:"<
for(int i=0;i<3;i++)
myfile<<"Marks:"<
myfile.close();
}
else
{
if(c=='N')
display();
else
cout<<"Please Enter Proper Option"< }
getch();
return 0;
}
void display()
{
cout<<"Name :"< cout<<"Age :"< cout<<"Address :"< for(int i=0;i<3;i++)
cout<<"Marks: "<<"is"< }
void getData()
{
cout<<"Enter name:";
cin>>name;
cout< cout<<"Enter age:";
cin>>age;
cout< cout<<"Enter address:";
cin>>add;
cout<<"Enter Marks:"< for(int i=0;i<3;i++)
{
cout<<"Enter Marks for 3 Subject :";
cin>>marks[i];
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.