Comment

Todd Little
Facilities,
August 25, 2009 at 9:48 PM

How would you add a loop to this program.


#include <iostream>
#include <string>
#include <fstream>
using namespace std;


int main()

{

cout<<"Todd Little"<<endl;
cout<<"CIS326"<<endl;
cout<<"Quiz#3"<<endl;
cout<<"The raw data from the data file:"<<endl;
cout<<"Computer Programming Book Challenging Spring C++ JAVA Winter Fall Garden GLobal/n"<<endl;
cout<<" Warning BrokenJaw Book Cup_of_Tea Art Plotter Printer Mouse Cat House Shoes TV-Ad/n"<<endl;
cout<<" Book BrokenCar EndlessCar EndlessSummer FullofEnergy"<<endl;




char inName[16],outName[16];

string s1,s2,s3;

s1="Search for a word:Program then checks to see if a word entered by a user is in the data";
s2="If the word is in the data then reports how many times the word is repeated in the data ";
s3=s1+s2;

cout<<s3<<endl;

// with no arguments
//s1=[15];





//ask user enter the input file name
cout<<"enter complete imput file name(limit is 15 characters)"<<endl;
cin.getline(inName,15);

//ask user enter the output file name
cout<<"enter complete output file name(limit is 15 characters)"<<endl;
cin.getline(outName,15);

//with argument

//open input file
ifstream input(inName);

//close program if file did not open correctly
if(!input)
{
cerr<<"\nInput file erorr!Check and run program again";
exit(1);
}//end if

int count =0;
string temp;
while (!input.eof())
{
count++;
input>>temp;
}


//set pointer to the beginning of the file
input.clear();
input.seekg(0);

//create an array of string having the dimesion equal to the number of data
string* cS = NULL;
cS = new string[count];

for (int i=0;i<count;i++)
{
input>>cS[i];
}

cout<<"Data in the file is "<<endl;

for (int j=0;j<count;j++)
{
cout<<cS[j]<<endl;
}

string search_word;
cout<<"Enter the search word"<<endl;
cin>>search_word;

for (int k=0;k<count;k++)
{
if (cS[k] == search_word)
{
cout<<"Found word " + search_word + " in file"<<endl;;

return 0;
}
}

cout<<"Failed to find word " + search_word + " in file"<<endl;

return 0;
//To check the dynamic array, program must display the raw data direcly from the array
//Program then checks to see if a word enterded by a user is in the data
//Program then allows user to replace a word in the data file
//Program stores the data in an output file
//int main()
//{
//}


//sreturn (s1+s2[0]+s2[1]+s2[2]);

}
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
C++

C Tutorials
C Tutorials       In this section we have given large number of tutorials on C... will be needing a C compiler on your machine. Here are the tutorials of C 

Blog

Site map - C Tutorials
; | XPath Tutorials | HTML Tutorials C Tutorial Section C String Reverse... for loop | C Break with Switch statement  | C String length | C array...; C Tutorials  | Java Tutorials | PHP Tutorials  | Linux 

C Tutorials

C String length
C String length       In this section, you will learn how to determine the length of a String in C. You can see in the given example, we have declared a string and initialize 

Programming Tutorials

C++Tutorials
other tutorials, such as C++: Annotations by Frank Brokken and Karel Kubat...; The CPlusPlus Language Tutorial These tutorials explain the C++ language... Borland C++ Builder 3 Page -Tutorials This section of my Builder web 

CVS Questions

c++
c++  Write a console based C++ program that reads student information... name with the minimum GPA 7) Display Student GPAs as Letter Grades (A, B, C, D...: ID: int FirstName: string SecondName: string FirstExam: int SecondExam 

Development process Questions

c++
c++  write a programme that calculates the area and circumference of a rectangle   #include<conio.h> #include<iostream.h>... Enter length and breath of the rectangle :"; cin>>l>>b; } void calc 

Java Beginners

String length without using length() method in java
String length without using length() method in java  How to count length of string without using length() method in java?   Here is Example...) { i++; } System.out.println("String length : " + i 

Mobile Applications Questions

convert char to string objective c
convert char to string objective c  Converting char to string in objective c   NSString *s = [[NSString alloc] initWithBytes:arr + 2 length:3 encoding:NSUTF8StringEncoding 

Java-Tutorials

Java : Length of String
Java : Length of String In this tutorial we are going to write logic to count the length of specified String. Length of String : Length of string means the number of characters in your String. There is many way to find out the length 

Java Tips and Examples

String length example
String length example     ... the length of string. You will see in the following program for getting the length of string by using the length() method that returns integer type value of any 

Tutorials

NSString in objective c
NSString in objective c In this series of Iphone application development tutorials, we going to introduce you with some of the iphone basic classes and objects...that are used in objective C. NSString is one of them. Brief Introduction 

Mobile Applications Questions

objective c if string equals
objective c if string equals   Checking if a string is equal to ' " '   In objective c, isEqualToString is a keyword that allows you to check if the string is equal to or not. if ([text isEqualToString 

Mobile Applications Questions

Parsing string in objective c
Parsing string in objective c  Hi, How can i parse a string in Objective c?? Thanks.   Parsing string in objective c This example will also help you to separate the strings separated by one component 

Mobile Applications Questions

copy string to string objective c
copy string to string objective c  How to copy a value of NSString to another string in Objective C? I have to different views and i am will to show the NSString value in both of them. Thanks 

Java Beginners

c c++ - Java Beginners
]; String name = f[1]; String c = f[2]; String note = f[3...]; String name = st[1]; String c = st[2]; String note = st[3]; if (id.equals... = f[1]; String c = f[2]; String note = f[3]; if (!id.equals(t1 

Swing AWT

c c++ - Swing AWT
c c++  Write Snake Game using Swings  Hi Friend, Try...); } public static void main(String[] args) { new SnakeGame(); } } 2... gameOver(Graphics g) { String msg = "Game Over"; Font small = new Font("Helvetica 

Ajax Questions

c#
c#  how to find out the size of the BMP image in C 

CVS Questions

C++
C++  How can i write this in dev c 

Development process Questions

C++
C++  How can i write this in dev c 

Java Beginners

C# question
C# question  In C#, string is a class or primitive type. Explain 

Development process Questions

c++
c++  use a prgrm as an example to xplain-: a)class b)object c)message d)cope resolution operator 

Java Beginners

C/C++/JAVA Question on function
C/C++/JAVA Question on function  "Write a function to find out common alphabets between two arrays. Length of array is not fixed and may contain other data type also.√Ę‚?¨¬? Question can be solved in C,C++ or JAVA 

Ajax Questions

c#
c#  how to find out the size of the BMP image 

Development process Questions

c++
c++  write a programme that calculates the area and circumference of a rectangle 

Development process Questions

C++
C++  dear sir How to create windows form application for login screen using C++? USER Name -TESTADMIN Password -testuser 

Java Beginners

c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used 

Java Beginners

c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used 

Java Beginners

c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used 

Development process Questions

C++
C++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples 

Development process Questions

c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples 

Development process Questions

c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples 

Design concepts & design patterns Questions

C++
C++  Trace the bubble sort using the following integers,which represent the elements in an array. 5,7,3,8,6,7,3 

Development process Questions

c++
c++  write a prgrm tht accepts 3 integer values,then with a function to swap the values 

Java Beginners

C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack 

Development process Questions

C++
C++  I have been asked to write a programme that gets five values,gets the sum,average and product please help me 

Java Beginners

C#
C#  i need a code that will make program perform the basic operations upon the data Listview save, update and cancel 

Development process Questions

C#
C# register form  i want to generate a user id automatically after filling their register form and i want to show their id to their email? please reply me soon 

UML Questions

c++
c++  Consider the following function: int funcExercise7(int list[], int size) { int sum = 0; for (int index = 0; index < size; index++) sum = sum + list[index]; return sum 

UML Questions

c++
c++  Consider the following declarations: class xClass { public: void... private members does class xClass have? c. How many constructors does class xClass.... Write a C++ statement that prints the values of the data members of the object 

Development process Questions

c++
c++  .write a program that accepts 5 subjects of a student,it should have a function to calculate the average & another function to grade.grade should be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70 

Development process Questions

c++
c++  write a prgrm tht calculates the surface area of a cylinder.the prgrm shld find the circumfrance and have a function that calculates the fadius and another to calculate the surface area 

Development process Questions

C++
C++  write a prgrm tht gets five values,gets the sum,average &...; #include <conio.h> void main() { clrscr(); int a,b,c,d,e,sum; float average...;>b>>c>>d>>e; sum=a+b+c+d+e; average=sum/5; product=a*b*c*d 

Spring Framework Questions

c++
c++  write a program that gets a key or character from the keyboard and displays it ASII code in decimal, hexadecimal and binary form.It must also give a description of the key pressed 

UML Questions

c++
c++  Consider the following declarations: class xClass { public: void func(); void print() const; xClass (); xClass (int, double); private: int u... private members does class xClass have? c. How many constructors does class xClass 

UML Questions

c++
c++  Characterize the following algorithm in terms of Big-O notation. Also find the exact number of additions executed by the loop. (Assume that all variables are properly declared.) for (int i = 1; i <= n; i++) sum = sum + i 

UML Questions

c++
c++  Characterize the following algorithm in terms of Big-O notation. for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) cout << i + j + k 

UML Questions

C++
C++  . Consider the definition of the following class: class CC { public: CC(); //Line 1 CC(int); //Line 2 CC(int, int); //Line 3 CC(double, int); //Line 4 . . . private: int u; double v 

Development process Questions

c++
c++  .write a prgrm tht accepts 5 subjects of a student,it shld hv a function to calculate the average & another function to grade.grade shld be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70 

UML Questions

c++
c++  Write the definition of the class dayType that implements the day of the week in a program. The class dayType should store the day... on an object of type dayType: a. Set the day. b. Print the day. c. Return the day 

Java Beginners

c++
c++   Assume vector "x" of integers with values of 7, 3, 5, 8, 1, 9, 0, 4, 2, 6. Second, assume integer variables "a," "b" and "y" with values of 3, x.size()-5 and 0, respectively. Third, assume a for-loop header which: 3.1 

Development process Questions

c programing
c programing  Write 2 implementations of C's string copy routine, one with a loop and the other using recursion. What is the security risk with this routine? The function should have the signature: char* strcpy(char* destination 

Development process Questions

c programing
c programing  Write 2 implementations of C's string copy routine, one with a loop and the other using recursion. What is the security risk with this routine? The function should have the signature: char* strcpy(char* destination 

Java Tips and Examples

length() Method In Java
of the String class. We are going to using length() method. These method... many character of length in String. First of all, we have to define class named... values. So we are using to length() method of the String class for the purpose 

SQL Tutorial

SQL Length Function
SQL Length Function       Length Function in SQL is used to return the length of a column, string or variable in bytes or characters. Understand with Example 

Java Beginners

C language
C language  i want that when i hit any key only * to be print not the hit key in c language   The given example will display aestricks... main() { char data[15]; /* max length 14 characters say */ int index 

Java Beginners

How to get length of string in Java?
How to get length of string in Java?  What is the method of String for getting the length? How to get length of string in Java? Tell me code fast... Tutorials"; int length = str.length(); You have to use the str.length() to get 

Programming Tutorials

C++GraphicsTutorials
C++ Graphics Tutorials     ... in this document is correct. C/C++ Windows programmers who want to learn... MFC.      OpenIL in Dev-C++ OpenIL 

Java Beginners

programming c#
programming c#   create and make use of at least one class with appropriate instance methods to solve the programming problem. use console-based... on the console window. predefine methods of the "string" and "math" class should be used 

Ajax Questions

c++ new, delete, string class
c++ new, delete, string class  Write one program containing all these string exercises. Read a string from the user into a string named string1... contained in string1: Exercise 1 Good morning Create a new string named string2 

Design concepts & design patterns Questions

classes in c++
classes in c++  1- design and implement a class datatype...) { return (day + days) % 7; } public String toString... ""; } public static void main(String[] args 

Programming Tutorials

SQL Length Function
SQL Length Function       Length Function in SQL is used to return the length of a column, string or variable in bytes or characters. Understand with Example 

Development process Questions

C,C++
C,C++  Sir, 100&30 gives output 4 in C++ and 100|30 gives output 116 How & and | gives output 4 and 116 

C Tutorials

C Array length example
C Array length example       In this section you will learn how to determine the length of an array in C. An array is a contiguous group of data items with the same name 

Development process Questions

C,C++
C,C++  int i=100,j=20; int c=i&j; int r=i|j; printf("%d",c); printf("%d",r);   #include<stdio.h> #include<conio.h> void main(){ int i=100,j=20; int c=i&j; int r=i|j; printf("%d",c); printf("%d",r 

JSP Tutorials

Use of <fn:length(String)> Tag of JSTL
Use of <fn:length(String)> Tag of JSTL  ...; <c:out value="${fn:length(text)}"/>... wants to calculate the length of string 'mahendra singh'..... When user 

C Tutorials

C String Reverse
C String Reverse      ... the method, we are calculating the length of a specified string using a library function strlen(). Then string st[i] and st[strlen(st)-i-1] are swapped as: c= st[i 

Development process Questions

all c library functions
all c library functions  hi dear c coders, i need all c library functions with a detailed explanation. Who can give me usefull link? thanks beforehand!   Hi Friend, Please go through the following link: C Tutorials 

SQL Question

C program - SQL
C program  Thank You . Write some C programs using pointers . Write some C programs using files. Please reply me .   Hi Friend, Please visit the following link: http://www.roseindia.net/c 

Mobile Applications Questions

Select string from array in objective c
Select string from array in objective c  Hi, I wanted to select a string from the database table in objective c. But somehow it is not working..can-you suggest anything regarding the fetch query in objective c? Thanks.   

Java Interview Questions

about c and java
://www.roseindia.net/c-tutorials/ http://www.roseindia.net/interviewquestions...about c and java   i need java and c language interview and objective questions with answers for the fresher.please provide to me   Please 

Java Beginners

c program - Java Beginners
c program  Write a program to encrypt a string and decrypt 

Mobile Applications Questions

match string to regular expression - Objective C
match string to regular expression - Objective C  How to match string value to regular expression in objective c?   Use NSPredicate. See the example given below... NSString *searchString = @"loginStatus"; NSString 

C Tutorials

C String to Int
C String to Int       In this section, you will learn how to convert a string represented value into an integer represented value in C. You can see in the given example that we 

C Tutorials

C String Substring
C String Substring       In this section, you will learn how to get the substring from a string in C. You can see in the given example, a string and a method substring 

C Tutorials

C String Copy
C String Copy       In this section, you will learn how to copy the string in C. You can see in the given example, two string variables st1 and st2 are created. A string 

Framework Questions

c postfix - Framework
://www.roseindia.net/c-tutorials/index.shtml Thanks...c postfix  q: write a c program to read apostfix expression store it in array of character then evaluate this expression using eval and get_token 

IoC Questions

c program - IoC
c program  given the string "wordprocessing",write a program to read the string from the terminal and display the same in the following formats: a) word processing b) word processing c) w.p. 

Java Beginners

c++ program of inheritance
c++ program of inheritance   Assume that a bank maintains two kinds... facilities but no cheque book facility. The current account provides cheque book.... (b) Display the balance (c) Compute and deposit interest. (d) Permit 

Java Beginners

help with substring in c programing
help with substring in c programing  Hi I could not found programming in C in the "select category" so I am posting my question in java section... whether or not the second string is a substring of the first string. Regards 

Development process Questions

c/c++ - Development process
c/c++  Creating animation using c/c++. The code for moving an object using c/c 

Mobile Applications Questions

Why NSString Objective C
C and how to define and initialize the NSString Class?   Why NSString Objective C NSStrings is a class that deals with strings in objective c... = @"hello world"; You can also compare a string using the "isEqualToString 

Framework Questions

C# Error - Framework
C# Error  Please Solve The Following Error & Post Reply Error... button1_Click(object sender, EventArgs e) { string... for c# error 

General

C Tutorials
C       Java...; Java for C Developers Some times ago, many people believed that Java was slower than C because Java had to run through a virtual machine.   

Development process Questions

C Programming SubString Program
C Programming SubString Program  Sir I want to Check whether the Single Substring is present in the given 3 string. characters. eg if i entered First String- CPROGRAMMING Second String- CPROGRAM third String- PROGRAMMING if i 

C Tutorials

C String Join
C String Join      ... length1 and length2 to 0. Then consider the length1 as the length of the string s1 and length2 as the length of string s2.  Now set the length2 to 0 

Java Beginners

variable declaration in c and c++
variable declaration in c and c++  Comparison and an example of variable declaration in C and C 

Development process Questions

c/c++ - Development process
c/c++  I need the code for developping two dice and roll them using c/c++. Thanks 

HTML Questions

Visual studio C#
Visual studio C#  Create a class called Employee that includes three pieces of information as instance variables√Ę‚?¨‚??a first name (type string), a last name (type string) and a monthly salary (decimal). Your class should 

Hibernate Questions

C++ Question 2
C++ Triangle and Rectangle - calculate area of Triangle and rectangle using data members from base class  2.create class. Shape accepts two values... will treated as length and breadth of rectangle. #include<iostream.h> 

C Tutorials

C String Compare
C String Compare      ... by one. The library function gets() get the entered string from the console. The function strlen() determines the length of the strings and the function strcmp 

General

C Tutorials
 

Development process Questions

C++ program not running
C++ program not running  Hi, this program need to ask 10 random questions with a random month name. Example: RUN How many days... namespace std; int main() { cout< string names[12] = {"January", "February 

Java Beginners

C# - Java Beginners
C#  program to print the following: 1 1 1 1 2 2 1 2 3 3 3 2 3 4 4 4 4 3 4 5 5 5 5 5 4  Hi Friend, We are sending... main(String[] args){ for(int i=1;i<=2;i++){ for(int j=1;j<=i;j 

Development process Questions

C/C++ - Development process
C/C++  I need the code for playing the backgammon game using C/C++.Im using turbo C. I`ve already design the board.I badly need the code for playing this game 

Java Beginners

basic c/c++ questions
basic c/c++ questions  Are the Control statements like if(),while() in built functions? if no, why not as they satisfy all the properties of a function 

Java Beginners

basic c/c++ questions
basic c/c++ questions  Are the Control statements like if(),while() in built functions? if no, why not as they satisfy all the properties of a function 

Java Beginners

C/C++ QUESTIONS
C/C++ QUESTIONS  ‚??Write a function for finding out the occurences of repeated word from a sentence. This function would return an array of duplicate words.‚ 

Development process Questions

c/c++ - Development process
c/c++  Ive been asked to develop a backgammon game using C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks 

Development process Questions

c/c++ - Development process
c/c++  Ive been asked to develop a backgammon game using C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks 

Java Beginners

c c++ - Java Beginners
c c++  Write a Multi-user chat server and client  Hi Friend, Please visit the following link: http://www.roseindia.net/chatserver/index.shtml Hope that it will be helpful for you. Thanks 

Advertisements Advertisements
 

 

 

DMCA.com