Question

In: Computer Science

void main() {     Grade g1; //object for grade     char h;     cout << "enter...

void main()
{
    Grade g1; //object for grade
    char h;

    cout << "enter character" ;
    cin>>h; //getting value
    g1.grade(h);
    g1.print();

   getch();
}

create an output file (named “output.txt”), and save the character to this output file. Last, close this output file

Solutions

Expert Solution

#include <fstream>
#include <iostream>
#include<conio.h>
using namespace std;
class Grade { // The class
      public:              // Access specifier
        void grade(char h) {
          ofstream file;
          file.open("output.txt");
          file<<h; //writing character to file output.txt
          file.close(); //closing file
        }
        void print(){
            ifstream infile;
            char ch;
            infile.open("output.txt"); //open output.txt file
            infile>>ch; //reading character from file
            cout<<"printing character:"<<ch;
        }
};
int main()
{
        Grade g1; //object for grade
        char h;
        cout << "enter character: " ;
        cin>>h; //getting value
        g1.grade(h); //calling grade method inside Grade class
        g1.print(); //calling print method
    
        getch();
        return 0;
}

OUTPUT

output.txt file


Related Solutions

convert the code to the flow chart char counter; void wait() { delay_ms(1000); } void main()...
convert the code to the flow chart char counter; void wait() { delay_ms(1000); } void main() { TRISB=0x00; // set direction to be output PORTA=0x00; // turn off the PORTA leds PORTB=0x00; // turn off the PORTB leds PORTC=0x00; // turn off the PORTC leds PORTD=0x00; // turn off the PORTD leds while (1){ for (counter = 15; counter>0 ; counter= --) { PORTB = counter; wait(); } } }
import java.util.Scanner; public class test {    public static void main(String args[]){        char letter;...
import java.util.Scanner; public class test {    public static void main(String args[]){        char letter;        int number = 0;        Scanner in = new Scanner(System.in);        System.out.print("Enter a letter: ");        letter = in.next().charAt(0);        if(letter == 'A' || letter == 'B' || letter == 'C') number = 2;        if(letter == 'D' || letter == 'E' || letter == 'F') number = 3;        if(letter == 'G' || letter ==...
A sag vertical curve is to join a grade of g1=−3.50% to a grade of g2=−1.25%....
A sag vertical curve is to join a grade of g1=−3.50% to a grade of g2=−1.25%. What is the minimum length of the curve for acceptable passing sight distance at night, with headlight illumination? Express your answer in feet to five significant figures. there is no more info. this is all that was given to us.
public class GreeterTest {    public static void main(String[] args)    { // create an object...
public class GreeterTest {    public static void main(String[] args)    { // create an object for Greeter class Greeter greeter = new Greeter("Jack"); // create two variables Greeter var1 = greeter; Greeter var2 = greeter; // call the sayHello method on the first Greeter variable String res1 = var1.sayHello(); System.out.println("The first reference " + res1); // Call the setName method on the secod Grreter variable var2.setName("Mike"); String res2 = var2.sayHello(); System.out.println("The second reference " + res2);    } }...
import java.util.Scanner; public class Lab5 { public static void main(String[] args) { final char SIDE_SYMB =...
import java.util.Scanner; public class Lab5 { public static void main(String[] args) { final char SIDE_SYMB = '-'; final char MID_SYMB = '*'; Scanner scanner = new Scanner(System.in); String inputStr = ""; char choice = ' '; int numSymbols = -1, sideWidth = -1, midWidth = -1; do { displayMenu(); inputStr = scanner.nextLine(); if (inputStr.length() > 0) { choice = inputStr.charAt(0); } switch (choice) { case 'r': System.out.println("Width of the sides?"); sideWidth = scanner.nextInt(); System.out.println("Width of the middle?"); midWidth = scanner.nextInt();...
import java.util.Scanner; public class Grade { public static void main(String[] args) { Scanner scnr = new...
import java.util.Scanner; public class Grade { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); // Reading score from user System.out.println("Enter the student's score:"); double score = scnr.nextDouble(); System.out.print("Grade:"); // Checking if score is less than 60 if(score<60){ System.out.println("F"); } // Checking if score is less than 70 else if(score<70){ System.out.println("D"); } // Checking if score is less than 80 else if(score<80){ System.out.println("C"); } // Checking if score is less than 90 else if(score<90){ System.out.println("B"); } // Checking...
A grade g1=+2.00% intersects grade g2=−1.40% at a vertex whose station and elevation are 78+60 and...
A grade g1=+2.00% intersects grade g2=−1.40% at a vertex whose station and elevation are 78+60 and 7855.35 ft, respectively. An equal-tangent parabolic curve 505 ft long has been selected to join the two tangents. Compute station elevations for the curve, for stakeout at full stations.
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10];...
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10]; printf("Starting the CPSC 1011 Decimal to Binary Converter!\n"); while(1) {    i=0;    printf("\nPlease enter a positive whole number (or EOF to quit): ");    scanf("%s", input); // user inputs value as a string for separate values    if(strcmp(input,"")==0) {        printf("\n\tThank you for using the CPSC 1011 Decimal to Binary Generator.\nGoodbye!\n\n");    return(0); } num=atoi(input); if (num<=0) {    printf("\n\tSorry, that was...
Python file def calci(): grade = float(input("Enter your grade:")) while (grade <= 4): if (grade >=...
Python file def calci(): grade = float(input("Enter your grade:")) while (grade <= 4): if (grade >= 0.00 and grade <= 0.67): print("F") break elif (grade >= 0.67 and grade <= 0.99): print("D-") break elif (grade >= 1.00 and grade <= 1.32): print("D") break elif (grade >= 1.33 and grade <= 1.66): print("D+") break elif (grade >= 1.67 and grade <= 1.99): print("C-") break elif (grade >= 2.00 and grade <= 2.32): print("C") break elif (grade >= 2.33 and grade <=...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your code should use pointer arithmetic (it may increment and decrement pointers, but it may not use array indexing). Here is a piece of code that shows the behavior of reverse: char buf[100]; strcpy(buf, “hello”); reverse(buf); printf(“%s\n”, buf); // output should be olleh
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT