hello guys i want someone help me with this work File Input/Output Use – Ch 6 Yo
ID: 3768298 • Letter: H
Question
hello guys i want someone help me with this work
File Input/Output Use – Ch 6
Your program must draw data from a file and write back to a file. Where you clearly show the use of an input file, storing, modification and then saving back to an output file. A way to show use would be to copy lines of code that demonstrate this such as.
Arrays – ch 7
Your program must store data in an array and modify that data. You need to clearly show not only the declaration of the array, but also its use.
P. 406 Display 7.7 Lines: 17 - 25
Strings – ch 8
Declaration and use of a sting. P. 476 Lines 7 – 10.
Pointers – ch 9
Do/While P. 513 Display 9.2, Lines 7 - 13
Clearly showing declaration and use.
Classes – ch 10
Declaration and Use of a Class
Explanation / Answer
ch6
#include <stdio.h>
#include <conio.h>
main ()
{
char in_file[30], out_file[30];
FILE *fpin, *fpout;
int c;
printf("This program copies the source file to the destination file ");
printf("Enter name of the source file :");
scanf("%30s", in_file);
printf("Enter name of the destination file :");
scanf("%30s", out_file);
if((fpin=fopen(in_file, "r")) == NULL)
printf("Error could not open source file forreading ");
else if ((fpout=fopen(out_file, "w")) == NULL)
printf("Error could not open destination file forreading ");
else
{
while((c =getc(fpin)) != EOF)
putc(c, fpout);
printf("Destination file has been copied ");
}
getch();
return 0;
}
ch7
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main ()
{
int array[5]={1,2,3,4,5};
printf("array before operation:");
for(int i=0;i<5;i++){
printf("%d ",array[i]);
}
for(int i=0;i<5;i++)
{
array[i]=array[i]+array[i+1];
}
printf("array after operation:");
for(int i=0;i<4;i++){
printf("%d ",array[i]);
}
getch();
return 0;
}
ch8
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(){
char name[30];
printf("Enter name: ");
gets(name); //Function to read string from user.
printf("Name entered is : ");
puts(name); //Function to display string.
getch();
return 0;
}
OR
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(){
char name[20];
printf("Enter name: ");
scanf("%s",name);
printf("Your name is %s.",name);
getch();
return 0;
}
ch9
#include <stdio.h>
#include <conio.h>
main()
{
int i = 10;
do{
printf("%d ", i );
i = i -1;
}while ( i > 0 );
getch();
return 0;
}
ch10
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area() {return width*height;}
};
void Rectangle::set_values (int x, int y) {
width = x;
height = y;
}
int main () {
Rectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.