Question

In: Computer Science

C++ program to read line comments. This assignment will give you a little bit of practice...

C++ program to read line comments.

This assignment will give you a little bit of practice with string parsing.

Your task is to write a program that reads in a .cpp file line-by-line, and prints out only the text that's after the // characters that indicate a single-line comment.

You do not have to worry about

/*
multiline comments
*/

though there will be a small amount of extra credit for programs that correctly extract these comments as well.

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
        fstream newfile;
        newfile.open("DynamicQueue.h", ios::in);
        if (newfile.is_open())
        {
                string tp;
                while (getline(newfile, tp))
                {
                        int i = 0;
                        for (i = 0; i < tp.size(); i++)
                        {
                                if ((i + 1) < tp.size())
                                        if (tp[i] == '/' && tp[i + 1] == '/')
                                                break;
                        }
                        i += 2;
                        int flag = 0;
                        while (i < tp.size())
                        {
                                cout << tp[i];
                                i += 1;
                                flag = 1;
                        }
                        if (flag == 1)
                                cout << endl;
                }
                newfile.close();
        }
}

Related Solutions

Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
In this assignment, you shall create a complete C++ program that will read from a file,...
In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
Assignment in C programming class: read the text file line by line, and place each word,...
Assignment in C programming class: read the text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. Assume tgat you will use no more than 1000 words in the text, and no more than the first 10 characters in a...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value parameters, using Java objects, and graphics. This assignment has 2 parts; therefore you should turn in two Java files.You will be using a special class called DrawingPanel written by the instructor, and classes called Graphics and Color that are part of the Java class libraries.Part 1 of 2 (4 points)Simple Figure, or your own drawingFor the first part of this assignment, turn in a file named...
(C++) All programs will be included! This lab gives you a little practice with linked lists...
(C++) All programs will be included! This lab gives you a little practice with linked lists ·Debug insertSorted() and implement sorted() in numberlist.cpp ·Hint: insertSorted() is just missing a few parts. What is in the function can work fine once you add the right code, though you are free to rewrite it ·You need to have main.cpp, numberlist.h and numberlist.cpp in this project, and if you are using Code::Blocks, remember to set the Build Options to indicate you want to...
C++ Progamming This lab gives you a little practice with stacks and queues ·In “stackfib.cpp”, write...
C++ Progamming This lab gives you a little practice with stacks and queues ·In “stackfib.cpp”, write a non-recursive function fib() which: ·Takes a single int parameter n ·Returns the nth Fibonacci number. We will start with fib(0) == fib(1) == 1, then fib(n) = fib(n-1) + fib(n-2) ·To compute this without using recursion, we use a stack to store the numbers we need to compute (1)   Initialize your result to be 0 (2)   Push the parameter n onto the stack (3)   While the...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT