Sponsored Content
Homework and Emergencies Homework & Coursework Questions C++ inputting multiple strings Post 302363453 by pondlife on Tuesday 20th of October 2009 10:20:23 AM
Old 10-20-2009
Power C++ inputting multiple strings

Hi All,

We've been given the exercise below and I'm stumbling at the first block because we have to take in 20 student names and I don't know how to store them! Smilie

I know that I can create (initialize) 20 different char arrays but this seems wrong somehow...

What's the best way to store these string inputs?

Thanks, p.

Quote:
Design, code and test a program, which accepts the names and examination marks
of 20 students, determine the grade for each student [Distinction (70 to 100), a
Merit (55 to 69), a Pass (45 to 54) fail (below 45). And displays the students’
names, their marks and grades. The output should look like:
Code:
Name Mark Grade
===== ===== =====
Sam 78 Distinction
Joe 54 Pass
………..


3. The attempts at a solution (include all code and scripts):

Code:
#include "stdafx.h"
#include <iostream>
#include <string.h>
using namespace std;

int main ()
{
	char aName[15];
	int aMark[15], iIndex;
	char cName;

	cout << "Enter Name and Mark: " << endl;

	for (iIndex = 0; iIndex < 15; iIndex++)
	{
		cout << "Enter Name: ";
		cin >> aName;


	}

	// test output
	for (iIndex = 0; iIndex < 6; iIndex++)
	{
		cout << "Name Array output: " << aName[iIndex] << endl;
		cout << "Mark Array output: " << aMark[iIndex] << endl;
	}

	return 0;
}

(obviously the above doesn't work...)



4. School (University) and Course Number:

Farnborough Tech - UK (C++ practitioners diploma)... Note this is NOT coursework it's just one of the examples we're given to work thru...

Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with inputting password

Hi all, In one of my script, somewhere I need to input password of a server when ssh password's prompt comes. I've tried with EOF but it's not taking. I don't want to disable password through ssh. I want the password should be passed with my script. Any suggestion? Thanks in advance! (2 Replies)
Discussion started by: naw_deepak
2 Replies

2. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

3. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

4. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

5. Programming

Inputting with SPACES...

I can't seem to successfully output characters with spaces. I inputted using getchar(). Any other ideas? Thank you in advance! printf ("Enter the Title : "); int i = 0; int c1; while (( c1!= '\n')&& (i <21)) { new_name->title = c1; i++; ... (0 Replies)
Discussion started by: Nephilim.F
0 Replies

6. UNIX for Dummies Questions & Answers

Inputting info

Hey guys! So I'm working on a program in linux terminal, using perl, to convert dna alignments to amino acid. It involves reading in one sequence and outputting another. I have it set so I can input a file but I can't input any sequences manually, anyone got any ideas about it? I have it set up... (0 Replies)
Discussion started by: PerlNutt
0 Replies

7. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

8. Shell Programming and Scripting

Grep multiple strings in multiple files

Hi, every one! I have a file with multiple strings. file1 ATQRGNE ASQGVKFTE ASSQYRDRGGLET SPEQGARSDE ASSRDFTDT ASSYSGGYE ASSYTRLWNTGE ASQGHNTD PSLGGGNQPQH SLDRDSYNEQF I want to grep each string in hundreds of files in the same directory, further, I want to find out the string... (7 Replies)
Discussion started by: xshang
7 Replies

9. Shell Programming and Scripting

Inputting multiple files into one command

I am trying to read 30 files into a command. The first file contains 10 lines and goes into this part of the command as "x" /tmp/filearrange.sh $x The group of files (20 files, I call them variable $i) need to be the second argument in the command and they need to be read so that they are... (9 Replies)
Discussion started by: newbie2010
9 Replies

10. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies
CGRULES.CONF(5) 						 libcgroup Manual						   CGRULES.CONF(5)

NAME
cgrules.conf - libcgroup configuration file DESCRIPTION
cgrules.conf configuration file is used by libcgroups to define control groups to which a process belongs. The file contains a list of rules which assign to a defined group/user a control group in a subsystem (or control groups in subsystems). Rules have two formats: <user> <controllers> <destination> <user>:<process name> <controllers> <destination> Where: user can be: - a user name - a group name with @group syntax - the wildcard '*', for any user or group - '%', which is equivalent to "ditto" (useful for multi-line rules where different cgroups need to be specified for various hierarchies for a single user) process name is optional and it can be: - a process name - a full command path of a process controllers can be: - comma separated controller names (no spaces) or - * (for all mounted controllers) destination can be: - path relative to the controller hierarchy (ex. pgrp1/gid1/uid1) - following strings called "templates" and will get expanded %u username, uid if name resolving fails %U uid %g group name, gid if name resolving fails %G gid %p process name, pid if name not available %P pid '' can be used to escape '%' First rule which matches the criteria will be executed. Any text starting with '#' is considered as a start of comment line and is ignored. If the destination contains template string, the control group can be created on-fly. In time when some process wants to use the template rule which leads to control group (see cgexec (1)) and the control group does not exist, the group is created. The template control group parameters can be specified in cgconfig.conf configuration file. See (cgconfig.conf (5)). If the template definition is not found there created group have default kernel setting. EXAMPLES
student devices /usergroup/students Student's processes in the 'devices' subsystem belong to the control group /usergroup/students. student:cp devices /usergroup/students/cp When student executes 'cp' command, the processes in the 'devices' subsystem belong to the control group /usergroup/students/cp. @admin * admingroup/ Processes started by anybody from admin group no matter in what subsystem belong to the control group admingroup/. peter cpu test1/ % memory test2/ The first line says Peter's task for cpu controller belongs to test1 control group. The second one says Peter's tasks for memory controller belong to test2/ control group. * * default/ All processes in any subsystem belong to the control group default/. Since the earliest matched rule is applied, it makes sense to have this line at the end of the list. It will put a task which was not mentioned in the previous rules to default/ control group. @students cpu,cpuacct students/%u Processes in cpu and cpuacct subsystems started by anybody from students group belong to group students/name. Where "name" is user name of owner of the process. FILES
/etc/cgrules.conf default libcgroup configuration file SEE ALSO
cgconfig.conf (5), cgclassify (1), cgred.conf (5) BUGS
Linux 2009-03-10 CGRULES.CONF(5)
All times are GMT -4. The time now is 05:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy