C++ :: Write Program That Outputs The Number Of Characters?
Jun 3, 2013
I need to write a program that outputs the number of characters, words, and lines in the files that are supplied as command-line arguments.
#include <iostream>
#include <string>
#include <iomanip>
[Code]....
View 2 Replies
ADVERTISEMENT
Aug 13, 2014
I assume floating point numbers in C++ have a default maximum of 5 decimal places. You can use setprecision() but is this limitless?
So how would find say write a program to calculate Pi to N number of places?
View 3 Replies
View Related
Sep 17, 2014
How we will write a program that will count a number of notes. I mean if i have 5676 rupees and i want to find the number of 5 thousand pak currency ,the number of 1000 notes, the number of 500 notes and the number of 100 notes. How we design such a program of if rlse structure to perform the above task.
View 1 Replies
View Related
May 2, 2014
So I need to write a program which tells the user if the number they input is prime or not. I have done so and included the code below. My problem is that I need to allow the user to input if they want to enter another number after the first one using y or n and I am having trouble figure it out.
#include <cstdlib>
#include <iostream>
using namespace std;
[Code].....
View 5 Replies
View Related
Jun 27, 2013
Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.
All I have so far is
string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;
I need to finish the rest in pseudo code
View 2 Replies
View Related
Sep 30, 2014
I am trying to do a simple for loop that computes sum of a certain number of integers and then outputs the sum.
.text
.globlmain
main:
li $9, 0
li $10, 0
li $11, 10
li $12, 0
li $13, 0
[Code] ....
There error I keep getting is on the line with the branch
Instruction references undefined symbol at 0x0040003c [0x0040003c] 0x10200000 beq $1, $0, 0 [exit-0x00400038]
View 1 Replies
View Related
Sep 2, 2014
I am trying to fill an array with blank spaces and instead i get the number 32 over and over, i think this is the ANSI code for that character. how do i get the character itself?
char values[max];
for(o=0;o<=max;o++)
{
values[o]=' ';
printf("%2d ", values[o]);
}
printf("
");
View 1 Replies
View Related
Mar 6, 2015
i m learning c programming and i m stuck with this program for some reason.Write a program that converts alphanumeric phone number into numeric form:
O/P:
Enter phone number: CALLAT 2255288
here is the code i have written:
/** compilers shows no error **/
and O/P I get is
Enter phone number: CALLAT
/**blank space***/
Code:
#include<stdio.h>
int main(void)
{
char ch;
printf("Enter phone number:");
ch=getchar();
}
[code]....
View 4 Replies
View Related
Nov 18, 2013
I have been asked to write a program to grade several multiple-choice exams. The exam has less than 80 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on several files such as exam1.dat where the first line is the key, consisting of a string of n characters (0<n < 80). The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of n characters.
The program should have a while loop in the main routine to ask users input a data file name through keyboard. In this way, the program has a capability of repeatedly asking for a new data file in each while loop until users input a key word “exit”. Once “exit” is encountered, the while loop terminates and your program ends. A typical input exam data file (exam1.dat) looks like:
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
Apply strlen( ) or the length( ) of string to the first line of the above data file for determining the number of questions in the problem. If a student gives more answers than necessary, the extra answers will be automatically truncated. On the other hand, if a student provides less number of answers, the remaining unanswered questions are considered as being answered wrongly.
After users input an exam data file, your program should ask users to input another grade-curving file name (e.g., gradeCurving.dat). This second file contains the information to convert a percentile score to a curved grade in levels of ‘A’ through ‘E’. For instance, a grade-curving file takes the following format: a curved alphabetic grade, a space, a percentile grade served as marker.
A 90
B 80
C 70
D 60
E 50
The above information means that ‘A’ = 90 through 100; ‘B’=80 through 89; ‘C’=70 through 79; ‘D’ = 60 through 69; “E”=50 through 59; For the remaining grades, you can assign an ‘F’.
Furthermore, in each while loop in the main routine, your program should ask users to input an output file name such as score1.dat. The output file will store the scores for each student in a format: student ID number, a space, a percentile score, and a curved grade in ‘A’ though ‘E’. The program should also compute and display the following statistics for the graded answers: Average score, Maximum score, and Minimum score.
A typical output on a data file looks like:
1234567 90% A
9876543 85% B
5554446 95% A
4445556 75% C
5551112 80% B
Statistics:
Average Score: 85%
Minimum Score: 95%
Maximum Score: 75%
This Is what I have so far. It compiles fine and everything but when I input the files it says "There was an error opening the corresponding files. Check input name perhaps?" and it exits out ....
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
int openfiles(ifstream& infile, ifstream& curvingfile, ofstream& outfile);
void Size(ofstream&,int,string);
[Code] ....
View 11 Replies
View Related
Mar 22, 2013
The program works, other than if I place the cursor below the last line in my merch file, the program outputs a line of garbage. The only solution I could find is to leave the cursor on the last line.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct vRecord {
string venue, item;
float price;
[Code]...
View 2 Replies
View Related
May 2, 2012
A program that outputs all numbers divisible by both 5 and 6.This is what i have written :
#include<stdio.h>
int main () {
int i=200;
int b=10;
while(i<1000)
i b/6%==0
}
where could i have gone wrong.
View 1 Replies
View Related
Oct 12, 2014
How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.
View 1 Replies
View Related
Oct 12, 2014
How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.
View 3 Replies
View Related
Dec 12, 2013
a program that allows the user to enter a statement and outputs statistics; number of vowels, number of constants, percentage of vowels and constants, number of words, number of punctuation characters
View 2 Replies
View Related
May 6, 2014
I need to do a code that gave me Original string, uppercase string, lowercase string, reverse string (if letter is upper then convert to lower, and if lower then convert it to upper) and uppercase first (first character of each word in uppercase).
I need to do it in functions but i dont know hot to use strings. The program should provide the option to save the outputs in a file.
View 4 Replies
View Related
Jun 20, 2013
I'm challenged to write a code for the following:
write a text up to 1000 characters, and get it back. the end of the text is detected though EOF on a new line or reaching 1000 characters.(EOF=ctr-Z on a new line)
I mainly have problem how to bring the EOF work probably. it doesn't react when I press ctrl-z directly?
Code:
int i;
char Text[1000];
printf("write the text:
");
gets(Text);
for(i=0;i<=1000;i++){
[Code] .....
View 3 Replies
View Related
Oct 13, 2014
Write a program that reads a string of characters including punctuation and writes what was read but with the punctuation removed.
This is how i did it:
string x("#punctuation!?=");
cout << x << endl;
for(unsigned i = 0; i < x.size(); ++i) {
if(ispunct(x[i]))
x[i] = ' ';
cout << x << endl;
I am just not sure if thats how they want you to do it because it doesn't remove the punctuations it just replaces them with a space.
View 3 Replies
View Related
Sep 30, 2013
For class I need to write a program that inputs a file (the dividend), performs binary division on the file (using 0x12 as the divisor), and outputs the remainder(checksum).
I have researched binary division algorithms and I get the general gist, but I'm still unsure where to start. How would I store the dividend and divisor? As two arrays of bits?
Then, I need to figure out how to perform shifts and XORs on the the binary numbers. Maybe I should use bitwise operations?
View 5 Replies
View Related
Jun 15, 2013
I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...
In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...
Follow the line number with a colon then 1 space, then the text of the line.
Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.
Here is what I have so far:
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;
[Code] ....
View 7 Replies
View Related
Mar 17, 2013
i am beginner in c++ , i need to write a programm that out ouputs a calender for a month when given a month and year using this frame work :
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
[code].....
View 8 Replies
View Related
Apr 4, 2015
This program must take user input(from stdin) that contains both a number and then a punctuation character, either a single quote(') or double quote(") that specifies feet or inches. It keeps prompting the user to enter a length until the user enters the sentinel value of 0. For example:
Enter a measurement and unit: 1'
Enter a measurement and unit: 2"
Enter a measurement and unit: 0
Total: 14 inches
The ultimate goal of this program is to then write an Assembly language program that is structurally similar and makes use of these 4 functions:
void printStr(char *)
Arguments:
edi = address of null-terminated string to print
Returns:
Nothing
[Code] ...
So here is what I have:
int main() {
char value[50];
char *end;
int sum = 0;
long conv;
while(conv !=0)
[Code] .....
I was told to use fgets instead of scanf for for stdin to parse the number and the quotation marks. I think I converted the number from string to integer correctly with strtol, but I really do not know how to obtain the (") or (') from user input so the program knows whether to convert the number to feet or just inches. No matter what I type in, even if it's without a quotation mark, it still multiplies the number by 12. In the IF and ELSE IF statement, it should state
if(value = ''')
and...
else if(value = '"')
View 4 Replies
View Related
Feb 22, 2015
I have recently hit a stump with C++ and have been getting pretty frustrated with this assignment. I just can't seem to find out how to start the assignment. Basically for the first part of the assignment, I need to find the number of characters in this .txt file my teacher provided for me. The only exception is that I can only count the actual letters themselves, not spaces or punctuation. How would I go about doing this? I have read about functions like isalpha but can't figure out on how to fit them into code to do the first part of this assignment.
View 2 Replies
View Related
Feb 3, 2014
I am looking for a way to correctly count the lines between two specified characters/strings in a file. Here's the part I need work on:
getline( file, lines );
do {
if(lines.find("character")
{
++counter;
}
} while( !lines.find("story") );
I want the code to search for the first occurence of the word "character," and start counting the lines from that line until it hit the first occurrence of the word "story."
Right now, I am only getting a counter value of 1.
View 2 Replies
View Related
Feb 1, 2014
I wrote a function to count the number of characters in a string. Curious as to why I have to return x-1 and why x isn't the number of characters.
Code:
int count(char *string){
55 int x = 0;
56 char *p;
57 p = string;
58
[Code] .....
View 4 Replies
View Related
Jul 21, 2014
I'm trying to copy a file into another file and copy the number of characters copied but my while loop doesn't even enter into a loop indicating the file is already at the EOF file character. I've confirmed this by placing the printf() statement inside the while loop, which doesn't print anything and by keeping it out of the while loop and changing the chars_copied to something like 9, it prints 9 for number of chars_copied. I don't understand why the file is already at the EOF character, I've tried this with a few more files, it's the same result.
Code:
#include <stdio.h>
int main(void){
FILE *input_file, *output_file;
int c, chars_copied=0;
if((input_file=fopen("C:workmarks.txt", "r"))==NULL)
perror("input file open failed");
[Code] ....
View 13 Replies
View Related
Feb 20, 2015
I have a text file which contains many sentences. I am trying to extract only the numerical values from the string that conatins characters,numbers and white spaces from the file. I want to seperate the characters and numbers into different parts.
for example: the file contains sentances as given below.
I have to go to school for 10min.
You will come here in 15min.
He stayed here for 20min.
from the above sentances, I want to seperate " I have to go to school for " and "10" and put them into two different variables and also 10 should be in integer format.
View 1 Replies
View Related