C++ :: How To Test A Program By Using Files Containing Tests
Sep 15, 2014How to test a program by using files containing tests and with a go file i think.
View 1 RepliesHow to test a program by using files containing tests and with a go file i think.
View 1 RepliesThe below program is supposed to display the contents of all files listed in the command line. When I try to run the program I get the fatal error "Debug Assertion Failed" Expression: file != NULL. I've done some researching on the matter and I gather it might be because I don't have any files listed in the command line?
How to enter files in the command line! I opened the Command Window in Windows XP and tried typing in "C> argc" and "% argc" (argc being the name of the file containing the below program) without any luck.
Code:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char * argv[]) {
int ch; // int to hold EOF
int count;
FILE *fp;
for(count = 1; count <= argc; count++) // agrc loop
[Code]...
How would I write a function that determines if a number is a multiple of another number.ex. (is 147 a multiple of 7?)
View 5 Replies View Related I am currently learning C and im in the middle of completing my assignment. It has to calculate parking whilst account for a few values here is the assignment sheet for specifics. Design Specifications Write, compile and test a C program with appropriate use..It's practically error less yet when i compile it doesn't come up with what i need.
Code:
/* Pre-Processor Directive */
#include <stdio.h>
#include <stdbool.h>
#define DISCOUNT_TIME_THREE 3
#define DISCOUNT_TIME_TEN 10
#define DISCOUNT_RATE_TWO 0.2
#define DISCOUNT_RATE_FOUR 0.4
[Code]....
I wrote a program to grade T or F test. It is running, but not outputting the information.
Code:
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
double grading(char*answer, char* stuResponse, double graded);
[Code] ...
text doc:
TFFTFFTTTTFFTFTFTFTT
ABC5403 TFTFTFTT TFTFTFFTTFT
ABC5404 TFTFFTTFFTFFFTTTFTFT
I am working on a program that calculates the average of a list of test scores entered, with the list ended with a negative score (which is not calculated), as long as a user enters a name.
#include<iostream>
#include<string>
using namespace std;
int main() {
string name;
double score = 0.0; //user input score
[code]....
I have gotten the while loop to function. The problem lies in the calculation in the average of the test scores, such as when I enter the scores 87 76 90 -1 , which is supposed to give an average of 84.3 but my result when outputted is 86. what the problem is and what I can do to fix this error?
Write a program that prompts for and reads in test scores. You may assume that valid test scores will be integer values between 0 and 100. You may also assume that the user will not enter more than 35 test scores. Use a preprocessor directive to define this value. User input will be complete when the user enters a -1 for the test score. When all of the test scores have been entered, the program will print out the scores. Use a while or do-while loop to read in the values. Use a for loop to print out the values.
Sample output:
Enter test score 1: 88
Enter test score 2: 67
Enter test score 3: 74
Enter test score 4: 94
Enter test score 5: 79
Enter test score 6: 56
Enter test score 7: -1
Number of scores entered: 6
Test scores entered : 88 67 74 94 79 56
I have created a program that allows for a user-defined number of test scores as input. After the user enters these scores, the program calculates the average test score. Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double getAverage(double*, int);
[Code] .....
I am having trouble with the final part of my program. How do I pass the array of test scores to a function that calculates how many people got an A (90+) on the test? The final output should look like this:
The average of those scores is:
The number of A grades is:
This is a program used to test navigating with arrows in a menu driven program
Whenever I run it it works but when I select any option it just producing a 'sound' but it doesn't print (cout) anything on the screen....
This program is just to test the arrow navigation and doesn't really modify,delete or add a new record but only prints stuff on screen.
#include<fstream.h> //for reading and writing files
#include<conio.h> //for clrscr()
#include<string.h> //for string characters
#include<stdio.h> //for gets and puts function
[Code] ....
I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.
The program is as follows:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
scanf("%75s", hostfile);
[Code]...
The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?
I have created a shared object in Ubuntu (libMYLIB.so). I am now trying to compile a simple test program (testmylib.c) to see if the shared object is properly built. I am getting an error that the build cannot find the shared object. My build command is:
gcc -lm -l /dir/mylib -lMYLIB.so -o testmylib testmylib.c
where /dir/mylib is where my source and libMYLIB.so reside.
What am I doing wrong?
I try to write my data into two different files and i just use something like this
ofstream myfile;
myfile.open("phase 1.txt");
if (myfile.is_open()) {
for(i=0;i<M; i++)
[Code] ....
But it only generate the first file. How should i modify this?
I want to use two header files in my program. Here is exactly what I want to do.
-In the first header I have a binary tree and a structure.
-In the second file I have another functions that need to use the structure in the first header.
-I also want to use a function from the second header in the first.
-And finally I want to do actions with both headers in a "main.cpp" file that contains only int main() function.
How to include the headers in each other and in the main.cpp to be able to do the actions above?
I try to include the first header in the second one and the second one in the first header. Then I include both headers in the main.cpp file. But the compiler shows me many errors.
program that I am working on. I want to use fgets() in my program so I could handle multiple words from a text(to be able to handle spaces). I get a weird result when running the program.
Code: #include <stdio.h>
#include <stdlib.h>
//#include "kim.h"
#include <string.h>
[code]....
-Create three files namely all_numbers, odd_number and even_number.
-Get the number of records and the numbers to store from the user.
-Save all the numbers in "all_numbers" file.
-Read each number and check whether it is odd or even.
-Store the odd numbers in odd_number file and even numbers in even_number file.
-Finally, print the numbers stored in odd_number and even_number files.
The output of the program will look like this.
How many records that you want to store :41
2
3
4
The data are written too the respective files.
The even numbers are 2 4
The odd numbers are 1 3
I understand I can do this via a php file on a server, but I don't understand how I can communicate with the php file from c++ code on my machine. Is there some library function I can use to load the html form or data object to hold the php form? Also whats the vibe on amazon EC2 cloud computing servers? It may be out of the scope of this simple program I have uploading and downloading XML, but is this the technology of the future, and should it be embraced now?
View 1 Replies View Relatedi am trying to doing my project what is: Diff - The program should compare two text files and list the differences, i.e. lines and columns of the beginning and the end of a given difference.
i dont know how to start or what to do with this.
'Write a program to match the user input string with the contents of text files and give the result as to which files contain the input string. This has to be done by using finite automaton.' (Any language can be used) So basically, the user will input a string (in the command line or a gui) and "we must pass the text files to the DFA" (I'm double quoting this because it's precisely what my professor told) and then display those files which contain the string. The string can be hard-coded, ie,the user will get the output file that contains a specific string. ex: 'hello'. The problem is, I have never done any program on DFA so I'm at a loss. how to write the program. Should I read the files first and then use some 'switch' or 'goto' conditions for the DFA? Below is a code I found on the internet for simulating a DFA accepting a specific string.
Code:
s: accept = false; cin >> char;
if char = "m" goto m;
if char = EOF goto end;
goto s;
m: accept = false; cin >> char;
if char = "m" goto m;
if char = "a" goto a;
if char = EOF goto end;
goto s;
}
[code]....
My program needs to compile various source files at runtime.What is the most elegant way to compile cross platform with g++ from within my program? Is there a gcc-library I can use? I know that I could use popen() to open a Unix pipe and call g++ as command line tool. But first it isn't really cross platform and second it doesn't seem elegant to me.
View 10 Replies View RelatedI want to make a program that can know the current time and create a new .txt file.For example if its Monday to day then when its Tuesday it crates a new txt file called Tuesday.I really don't know how to go about this.I know i will need to use the time.h library.
View 4 Replies View RelatedI am just wondering if it is possible to send a project to someone via email - In a simple way, almost like you would install software from the internet, maybe a setup file, or something. The compiler I use "Dev C++" creates a .cpp file and an executable. Unfortunately, I cannot send that .exe file. How would you recommend sharing a program?
View 5 Replies View RelatedI want to know how to read multiple text files in this program... I have 5 text files(order1,order2,...order5).
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<windows.h>
using namespace std;
class{
[Code] ....
I have written a C++ program that is supposed to open two text files (prog2a.dat and prog2b.dat) and write the contents of a specified range of lines to an output file (outfile.dat). I wrote a program that based on the example we were given (to take lines 5-15 from the first file and lines 4-12 of the second file and merge them into the output file) works perfectly. However, after asking my professor for some clarification on another part of the assignment, I found out I have not done this correctly. I have the code written so that it will always output the range of lines I mentioned earlier, but the program is actually supposed to allow the user to merge the files from the command line using whatever range they want by typing in the following command:
prog2 in1 5-15 in2 4-12 outfile
But I'm not sure how to tweak my current program to allow this to be done.
Here is the code that I have written, keep in mind that this works properly for the way it is written, but not how it is supposed to work for the purposes of the command line (hopefully that makes sense):
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main() {
// Create output file
std::ofstream outFile("outfile.dat", ios::out);
[Code] .....
Is there any simple way to make this work as I described using the command line? Also, I am supposed to break this up into three files, a header file, the program file, and a test file (the test file contains main() and should close the 3 open files and display any error messages), but I'm getting really confused as to what should go in the header file. I know the header file should contain class definitions and constructors, but don't really know how to make that work for this specific program?
I'm having an issue with merging two files. Basically, my instructor gave me pseudocode and two files to merge together. Each file (a male client and a female client file) has three names and id numbers inside. The finished MergedClients.rtf should have all six clients in ascending ID order. I wrote the C++ code and after combing through a couple times to fix a few errors, it finally ran. The problem is it starts the process, but it doesn't ever finish.
I tried changing some of the bool expressions thinking I mixed up the true and false parts. After that the program ran and it created the new output file, but the file was empty. So, I don't think I mixed any of those expressions after all.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream inFile1;
ifstream inFile2;
[code]....
I'm writing a code obfuscator in C. Debugger shows no errors in the code, but the program crashes after compiling -- I'm guessing it has something to do with while loops or reading data from files.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// list off all replaced elements
typedef struct ReplaceList {
char *from;// from string
char *to;// to string (random)
[Code] ....
I am working on a airport reservation program and i have run into a brick wall. i want to ask the user its name, gender, passport no, age, destination, and travel class and figure out the day and flight code of the flight which i have saved in a binary file. now every thing works fine except the code and the day.
The programs important section
the flight class Code:
class flights {
char code[9],location[21];
public:
void display();
char *retloc() //to get the Location
[Code] .....